Git實用命令速記
1、創建
克隆一個已存在的遠程版本庫到本地
$ git clone ssh://[email protected]/repo.git
創建一個新的本地版本庫
$ git init
2、本地修改
在工作區修改文件
$ git status
追蹤修改的文件(對比工作區與版本庫的區別)
$ git diff
添加所有當前修改到暫存區(下一次提交前)
$ git add
添加指定文件到暫存區(下一次提交前)
$ git add -p <file>
提交所有本地修改的文件
$ git commit -a
提交暫存區的文件
$ git commit
修改最後一次提交的信息(沒有推送提交之前)
$ git commit --amend
3、提交歷史
顯示從開始到最近的所有提交日志
$ git log
顯示指定文件的修改日志
$ git log -p <file>
顯示指定文件誰在哪些時間做了哪些修改
$ git blame <file>
4、分支和標簽
列出所有已存在的分支
$ git branch
切換分支並將當前版本指向該分支
$ git checkout <branch>
創建一個基於當前版本的新分支
$ git branch <new-branch>
創建一個基於遠程分支的新分支(與遠程分支做關聯)
$ git branch --track <new-branch> <remote-branch>
刪除一個本地分支
$ git branch -d <branch>
給當前提交打上一個標簽
$ git tag <tag-name>
5、更新和推送
列出所有當前已配置的遠程版本庫(-v為詳細顯示)
$ git remote -v
顯示一個遠程版本庫的信息
$ git remote show <remote>
添加並命名一個新的遠程版本庫
$ git remote add <remote> <url>
從遠程版本庫中下載所有修改,但不整合進當前版本
$ git fetch <remote>
下載修改並直接合並或整合進當前版本
$ git pull <remote> <branch>
推送本地修改到一個遠程版本庫
$ git push <remote> <branch>
在遠程版本庫上刪除一個分支
$ git push <remote> :<branch>
推送所有標簽(到遠程版本庫)
$ git push --tags
6、合並&重新定義(版本庫狀態)
將分支合並進當前版本
$ git merge <branch>
重新定義當前版本在分支上的狀態(沒有推送提交之前)
$ git rebase <branch>
終止一個重新定義
$ git rebase --abort
在解決沖突後繼續一個重新定義
$ git rebase --continue
使用配置合並工具保存沖突
$ git mergetool
手動編輯解決沖突並在解決沖突之後標記保存文件
$ git add <resolved-file>
刪除標記保存的文件
$ git rm <resolved-file>
7、撤銷
在工作目錄中丟棄所有本地修改
$ git reset --hard HEAD
丟棄指定文件的本地修改
$ git checkout HEAD <file>
撤銷一個提交(撤銷會產生一個新的提交)
$ git revert <commit>
回退到一個之前的提交,並丟棄之後的所有修改
$ git reset --hard <commit>
回退到一個之前的提交,並撤銷暫存區的修改(即重新放回工作區)
$ git reset <commit>
回退到一個之前的提交,並保留未提交的本地修改
$ git reset --keep <commit>
Git 的詳細介紹:請點這裡
Git 的下載地址:請點這裡
推薦閱讀:
Fedora通過Http Proxy下載Git http://www.linuxidc.com/Linux/2009-12/23170.htm
在Ubuntu Server上安裝Git http://www.linuxidc.com/Linux/2009-06/20421.htm
服務器端Git倉庫的創建(Ubuntu) http://www.linuxidc.com/Linux/2011-02/32542.htm
Linux下Git簡單使用教程(以Android為例) http://www.linuxidc.com/Linux/2010-11/29883.htm
Git權威指南 PDF高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm