开发者社区> bndy.net> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

Git Commands

简介:
+关注继续查看

Git Commands

Useful Commands

Commit with empty message

  1. git config --global alias.nccommit "commit -a --allow-empty-message -m ''"
  2. git nccommit

Undoing Things

  • Overwrite commit

    1. git commit -m 'initial commit'
    2. git add .
    3. git commit --amend
  • Unstaging a Staged File

    $ git add *
    $ git status
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
        renamed:    README.md -> README
        modified:   CONTRIBUTING.md
$ git reset HEAD CONTRIBUTING.md
Unstaged changes after reset:
M    CONTRIBUTING.md
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    renamed:    README.md -> README

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   CONTRIBUTING.md
  • Unmodifying a Modified File

    Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git checkout -- <file>..." to discard changes in working directory)
    
      modified:   CONTRIBUTING.md
$ git checkout -- CONTRIBUTING.md
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

  renamed:    README.md -> README
  • View all logs

git reflog

Push changes to new branch

  1. git checkout -b newBranch
  2. git push -u origin newBranch // -u is short for --set-upstream

New branch from remote

  1. git checkout -b localBranch origin/remote_branch

Stash Usage

git stash  // stash current changes
git stash pop  // pop last stash and remove from history
git stash save 'message'  // stash current changes with message
git stash list // show all stashes
git stash apply <id>  // apply <id> stash

Common Alias

  • git config --global alias.s "status"
  • git config --global alias.a "!git add . && git status"
  • git config --global alias.au "!git add -u . && git status"
  • git config --global alias.aa "!git add . && git add -u . && git status"
  • git config --global alias.c "commit"
  • git config --global alias.cm "commit -m"
  • git config --global alias.ca "commit --amend"
  • git config --global alias.ac "!git add . && git commit"
  • git config --global alias.acm "!git add . && git commit -m"
  • git config --global alias.l "log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset"
  • git config --global alias.ll "log --stat --abbrev-commit"
  • git config --global alias.lg "log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
  • git config --global alias.llg 'log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit"
  • git config --global alias.d "diff"
  • git config --global alias.master "checkout master"
  • git config --global alias.spull "svn rebase"
  • git config --global alias.spush "svn dcommit"
  • git config --global alias.alias "!git config --list | grep 'alias.' | sed 's/alias.(1)=(.)/1 => 2/' | sort"

Workflow with Git: Fork, Branching, Commits, and Pull Request

  1. Fork a repo.
  2. Clone the forked project to your local machine:

    `$ git clone git@github.com:USERNAME/<forked_repo>`
    
  3. Configure remotes:

    `$ git remote add upstream git://github.com/<origin_repo>`
    
  4. Create a branch for new feature:

    `$ git checkout -b my-new-branch`
    
  5. Develop on my-new-branch branch only, but Do not merge my-new-branch branch to the your master (as it should stay equal to upstream master)!!
  6. Commit changes to my-new-branch branch:

    $ git add .
    $ git commit -m "commit message"
  7. Push branch to GitHub, to allow your mentor to review your code:

    `$ git push origin my-new-branch`
    
  8. Repeat steps 5-7 till development is complete.
  9. Fetch upstream changes that were done by other contributors:

    `$ git fetch upstream`
    
  10. Update local master:

    $ git checkout master
    $ git pull upstream master

ATTENTION: any time you lost of track of your code – launch “gitk —all” in source folder, UI application come up that will show all branches and history in pretty view, explanation.

  1. Rebase my-new-branch branch on top of the upstream master:

    $ git checkout my-new-branch
    $ git rebase master
  2. In the process of the rebase, it may discover conflicts. In that case it will stop and allow you to fix the conflicts. After fixing conflicts, use git add . to update the index with those contents, and then just run:

    $ git rebase --continue

  3. Push branch to GitHub (with all your final changes and actual code):

    We forcing changes to your issue branch(our sand box) is not common branch, and rebasing means recreation of commits so no way to push without force. NEVER force to common branch.

    $ git push origin my-new-branch --force

  4. Created build for testing and send it to any mentor for testing.
  5. Only after all testing is done – Send a Pull Request.

    Attention: Please recheck that in your pull request you send only your changes, and no other changes!!
    Check it by command:
    git diff my-new-branch upstream/master

submodule

git submodule add submodule-repo path
git submodule update --init --recursive
git rm submodule-name
git rm submodule-name --cached

  1. =

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
git commit 规范【锦上添花系列】
git commit 规范【锦上添花系列】
19 0
Git奇技|随意删除某个commit
Git奇技|随意删除某个commit
28 0
DDL会产生两次commit操作
DDL操作为什么需要两次commit操作呢?
435 0
Git合并指定commit到当前分支
有时我们需要将指定的某一次commit合并到当前分支,比如线上的一次bugfix,只合并需要的commits。 首先,用git log或GitX工具查看一下你想选择哪些commits进行合并,例如: dd2e86 - 946992 -9143a9 - a6fd86 - 5a6057 [master] \ 76cada - 62ecb3 - b886a0 [feature] 比如,feature 分支上的commit 62ecb3 非常重要,它含有一个bug的修改。
1805 0
Git之简介及安装
简介    Git是一个分布式版本控制系统,GitHub相当于一个远程仓库,注册账号可免费获得Git远程仓库。   GitHub使用参考:https://guides.github.com/activities/hello-world/ 安装 说明:因笔者是运维,故此叙述linux下g...
971 0
比较git commit 两个版本之间次数
#!/bin/bash f1="$1*" f2="$2*" echo "第一个版本:"$f1 echo "第二个版本:"$f2 git log | grep "commit [0-9a-zA-Z]\{40\}"|awk 'BEGIN{count=0;} {commit[count]...
840 0
pb之autocommit
        autocommit顾名思义自动提交的意思,默认情况下autocommit是false,需要手动commit或者rollback来结束当前事务。
784 0
vim --Filter commands
命令也被称作是motion :help ! Filter commands  信息过滤 (filter) !==>tell vim to performing a filter operation !5G -> 从光标下向下5行执行过滤程序 (tell vim to start filter under cursor and go down 5 lines) :.
701 0
mysql: command not found

centos下安装好mysql后,se

4337 0
+关注
bndy.net
Hi, my name is Bing Zhang, I always focus on Java, .Net, Frontend, Database, CI and Docker.
3
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载