简明 Git 命令速查表
本文總結了git常用的命令,以便學習者使用時查閱~
?
幾個專用名詞的譯名如下
- Workspace:工作區(qū)
- Index / Stage:暫存區(qū)
- Repository:倉庫區(qū)(或本地倉庫)
- Remote:遠程倉庫
?
復制一個已創(chuàng)建的倉庫:
git clone ssh://user@domain.com/repo.git創(chuàng)建一個新的本地倉庫:
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"修改上次提交
請勿修改已發(fā)布的提交記錄!
把當前分支中未提交的修改移動到其他分支
git stash git checkout branch2 git stash pop列出所有stash
git stash list查看一個stash
git show stash@{0}刪除一個stash
git stash drop stash@{0}將指定的stash取出來
git stash apply stash@{1}將最后一個stash取出來,并刪除掉隊列中相應的值
git stash pop清空所有stash
git stash clear從當前目錄的所有文件中查找文本內容:
git grep "Hello"在某一版本中搜索文本:
git grep "Hello" v2.5從最新提交開始,顯示所有的提交記錄(顯示hash, 作者信息,提交的標題和時間):
git log顯示所有提交(僅顯示提交的hash和message):
git log --oneline顯示某個用戶的所有提交:
git log --author="username"顯示某個文件的所有修改:
git log -p <file>誰,在什么時間,修改了文件的什么內容:
git blame <file>列出所有的分支:
git branch列出所有的分支以及其對應的遠端分支:
git branch -vv切換分支:
git checkout <branch>創(chuàng)建并切換到新分支:
git checkout -b <branch>基于當前分支創(chuàng)建新分支:
git branch <new-branch>基于遠程分支創(chuàng)建新的可追溯的分支:
git branch --track <new-branch> <remote-branch>刪除本地分支:
git branch -d <branch>給當前版本打標簽:
git tag <tag-name>獲取本地標簽:
git tag刪除一個本地標簽:
git tag -d <tag-name>刪除一個遠端標簽:
git push origin :refs/tags/<tag-name>發(fā)布標簽:
git push --tags列出當前配置的遠程端:
git remote -v顯示遠程端的信息:
git remote show <remote>添加新的遠程端:
git remote add <remote> <url>下載遠程端版本,但不合并到HEAD中:
git fetch <remote>下載遠程端版本,并自動與HEAD版本合并:
git remote pull <remote> <url>將遠程端版本合并到本地版本中:
git pull origin master將本地版本發(fā)布到遠程端:
git push remote <remote> <branch>將本地branch1發(fā)布到遠程端branch2:
git push origin <branch1>:<branch2>刪除遠程端分支:
git push <remote> :<branch> (since Git v1.5.0) git push <remote> --delete <branch> (since Git v1.7.0)將分支合并到當前HEAD中:
git merge <branch>將當前HEAD版本重置到分支中:
請勿重置已發(fā)布的提交!
退出重置:
git rebase --abort解決沖突后繼續(xù)重置:
git rebase --continue使用配置好的merge tool 解決沖突:
git mergetool在編輯器中手動解決沖突后,標記文件為已解決沖突
git add <resolved-file> git rm <resolved-file>兩個分支的合并,將other-branch合并到main-branch中
git checkout <other-branch> git rebase <main-branch> git checkout <main-branch> git merge <other-branch>放棄工作目錄下的所有修改:
git reset --hard HEAD移除緩存區(qū)的所有文件(i.e. 撤銷上次git add):
git reset HEAD放棄某個文件的所有本地修改:
git checkout HEAD <file>重置一個提交(通過創(chuàng)建一個截然不同的新提交)
git revert <commit>將HEAD重置到指定的版本,并拋棄該版本之后的所有修改:
git reset --hard <commit>將HEAD重置到上一次提交的版本,并將之后的修改標記為未添加到緩存區(qū)的修改:
git reset <commit>將HEAD重置到上一次提交的版本,并保留未提交的本地修改:
git reset --keep <commit>?
最后附一張完整展示git流程的圖片
?
參考:
http://www.codeceo.com/article/git-command-guide.html
http://www.ruanyifeng.com/blog/2014/06/git_remote.html
http://git-scm.com/doc
?
總結
以上是生活随笔為你收集整理的简明 Git 命令速查表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于中值滤波算法,以及C语言实现(转)
- 下一篇: Android UI法宝的设计资源的开发