本文內容來自我fork 並翻譯的GitHub repo Git-Cheat-Sheet,若是內容有誤或有新內容補充,歡迎你們給我發issue。javascript
Git cheat sheet 讓你不用再去記全部的git命令。java
歡迎貢獻內容、修正語法錯誤,也歡迎添加你母語版本的Git cheat sheet。linux
$ git config --list複製代碼
$ git config --local --list複製代碼
$ git config --global --list複製代碼
$ git config --system --list複製代碼
$ git config --global user.name 「[firstname lastname]」複製代碼
$ git config --global user.email 「[valid-email]」複製代碼
$ git config --global color.ui auto複製代碼
$ git config --global core.editor vi複製代碼
<repo>/.git/config複製代碼
~/.gitconfig複製代碼
/etc/gitconfig複製代碼
# 經過 SSH
$ git clone ssh://user@domain.com/repo.git
#經過 HTTP
$ git clone http://domain.com/user/repo.git複製代碼
$ git init複製代碼
$ git status複製代碼
$ git diff複製代碼
$ git add .複製代碼
$ git add -p <file>複製代碼
$ git commit -a複製代碼
$ git commit複製代碼
$ git commit -m 'message here'複製代碼
git commit --date="`date --date='n day ago'`" -am "Commit Message"複製代碼
請勿修改已發佈的提交記錄!git
$ git commit --amend複製代碼
GIT_COMMITTER_DATE="date" git commit --amend複製代碼
git commit --amend --date="date"複製代碼
git stash
git checkout branch2
git stash pop複製代碼
git stash apply複製代碼
git stash drop複製代碼
$ git grep "Hello"複製代碼
$ git grep "Hello" v2.5複製代碼
$ git log複製代碼
$ git log --oneline複製代碼
$ git log --author="username"複製代碼
$ git log -p <file>複製代碼
$ git log --oneline <origin/master>..<remote/master> --left-right複製代碼
$ git blame <file>複製代碼
$ git reflog show複製代碼
$ git reflog delete複製代碼
$ git branch複製代碼
$ git branch -r複製代碼
$ git checkout <branch>複製代碼
$ git checkout -b <branch>複製代碼
$ git branch <new-branch>複製代碼
$ git branch --track <new-branch> <remote-branch>複製代碼
$ git branch -d <branch>複製代碼
將會丟失未合併的修改!github
$ git branch -D <branch>複製代碼
$ git tag <tag-name>複製代碼
$ git tag -a <tag-name>複製代碼
$ git remote -v複製代碼
$ git remote show <remote>複製代碼
$ git remote add <remote> <url>複製代碼
$ git fetch <remote>複製代碼
$ git remote pull <remote> <url>複製代碼
$ git pull origin master複製代碼
git pull --rebase <remote> <branch>複製代碼
$ git push remote <remote> <branch>複製代碼
$ git push <remote> :<branch> (since Git v1.5.0)
# or
git push <remote> --delete <branch> (since Git v1.7.0)複製代碼
$ git push --tags複製代碼
$ git merge <branch>複製代碼
請勿重置已發佈的提交!windows
$ git rebase <branch>複製代碼
$ git rebase --abort複製代碼
$ git rebase --continue複製代碼
$ git mergetool複製代碼
已解決衝突
:$ git add <resolved-file>
$ git rm <resolved-file>複製代碼
$ git rebase -i <commit-just-before-first>複製代碼
把上面的內容替換爲下面的內容:緩存
原內容:bash
pick <commit_id>
pick <commit_id2>
pick <commit_id3>複製代碼
替換爲:服務器
pick <commit_id>
squash <commit_id2>
squash <commit_id3>複製代碼
$ git reset --hard HEAD複製代碼
git add
):$ git reset HEAD複製代碼
$ git checkout HEAD <file>複製代碼
$ git revert <commit>複製代碼
$ git reset --hard <commit>複製代碼
git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature複製代碼
$ git reset <commit>複製代碼
$ git reset --keep <commit>複製代碼
.gitignore
文件前錯誤提交的文件:$ git rm -r --cached .
$ git add .
$ git commit -m "remove xyz file"複製代碼
$ brew install git-flow複製代碼
$ port install git-flow複製代碼
$ apt-get install git-flow複製代碼
安裝 git-flow, 你須要 wget 和 util-linux。app
$ wget -q -O - --no-check-certificate https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | bash複製代碼
git flow init複製代碼
下面操做建立了一個新的feature分支,並切換到該分支
git flow feature start MYFEATURE複製代碼
完成開發新特性。這個動做執行下面的操做:
git flow feature finish MYFEATURE複製代碼
你是否合做開發一項新特性?
發佈新特性分支到遠程服務器,因此,其它用戶也可使用這分支。
git flow feature publish MYFEATURE複製代碼
取得其它用戶發佈的新特性分支。
git flow feature pull origin MYFEATURE複製代碼
經過下面命令追溯遠端上的特性
git flow feature track MYFEATURE複製代碼
git flow release start RELEASE [BASE]複製代碼
建立 release 分支以後當即發佈容許其它用戶向這個 release 分支提交內容是個明智的作法。命令十分相似發佈新特性:
git flow release publish RELEASE複製代碼
(你能夠經過git flow release track RELEASE
命令追溯遠端的 release 版本)
完成 release 版本是一個大 git 分支操做。它執行下面幾個動做:
git flow release finish RELEASE複製代碼
不要忘記使用git push --tags
將tags推送到遠端
緊急修復來自這樣的需求:生產環境的版本處於一個不預期狀態,須要當即修正。有多是須要修正 master 分支上某個 TAG 標記的生產版本。
像其它 git flow 命令同樣, 緊急修復分支開始自:
$ git flow hotfix start VERSION [BASENAME]複製代碼
VERSION 參數標記着修正版本。你能夠從 [BASENAME]開始,
[BASENAME]`爲finish release時填寫的版本號
當完成緊急修復分支,代碼歸併回 develop 和 master 分支。相應地,master 分支打上修正版本的 TAG。
git flow hotfix finish VERSION複製代碼