
<a target="_blank"></a>
複制一個已建立的倉庫:
<code>$ git clone ssh://[email protected]/repo.git</code>
建立一個新的本地倉庫:
<code>$ git init</code>
顯示工作路徑下已修改的檔案:
<code>$ git status</code>
顯示與上次送出版本檔案的不同:
<code>$ git diff</code>
把目前所有修改添加到下次送出中:
<code>$ git add</code>
把對某個檔案的修改添加到下次送出中:
<code>$ git add -p <file></code>
送出本地的所有修改:
<code>$ git commit -a</code>
送出之前已标記的變化:
<code>$ git commit</code>
附加消息送出:
<code>$ git commit -m 'message here'</code>
送出,并将送出時間設定為之前的某個日期:
<code>git commit --date="`date --date='n day ago'`" -am "commit message"</code>
修改上次送出
請勿修改已釋出的送出記錄!
<code>$ git commit --amend</code>
把目前分支中未送出的修改移動到其他分支
<code>git stash</code>
<code>git checkout branch2</code>
<code>git stash pop</code>
從目前目錄的所有檔案中查找文本内容:
<code>$ git grep "hello"</code>
在某一版本中搜尋文本:
<code>$ git grep "hello" v2.5</code>
從最新送出開始,顯示所有的送出記錄(顯示hash, 作者資訊,送出的标題和時間):
<code>$ git log</code>
顯示所有送出(僅顯示送出的hash和message):
<code>$ git log --oneline</code>
顯示某個使用者的所有送出:
<code>$ git log --author="username"</code>
顯示某個檔案的所有修改:
<code>$ git log -p <file></code>
誰,在什麼時間,修改了檔案的什麼内容:
<code>$ git blame <file></code>
列出所有的分支:
<code>$ git branch</code>
切換分支:
<code>$ git checkout <branch></code>
建立并切換到新分支:
<code>$ git checkout -b <branch></code>
基于目前分支建立新分支:
<code>$ git branch <new-branch></code>
基于遠端分支建立新的可追溯的分支:
<code>$ git branch --track <new-branch> <remote-branch></code>
删除本地分支:
<code>$ git branch -d <branch></code>
給目前版本打标簽:
<code>$ git tag <tag-name></code>
列出目前配置的遠端端:
<code>$ git remote -v</code>
顯示遠端端的資訊:
<code>$ git remote show <remote></code>
添加新的遠端端:
<code>$ git remote add <remote> <url></code>
下載下傳遠端端版本,但不合并到head中:
<code>$ git fetch <remote></code>
下載下傳遠端端版本,并自動與head版本合并:
<code>$ git remote pull <remote> <url></code>
将遠端端版本合并到本地版本中:
<code>$ git pull origin master</code>
将本地版本釋出到遠端端:
<code>$ git push remote <remote> <branch></code>
删除遠端端分支:
<code>$ git push <remote> :<branch> (since git v1.5.0)</code>
<code>或</code>
<code>git push <remote> --delete <branch> (since git v1.7.0)</code>
釋出标簽:
<code>$ git push --tags</code>
将分支合并到目前head中:
<code>$ git merge <branch></code>
将目前head版本重置到分支中:
請勿重置已釋出的送出!
<code>$ git rebase <branch></code>
退出重置:
<code>$ git rebase --abort</code>
解決沖突後繼續重置:
<code>$ git rebase --continue</code>
使用配置好的merge tool 解決沖突:
<code>$ git mergetool</code>
在編輯器中手動解決沖突後,标記檔案為<code>已解決沖突</code>
<code>$ git add <resolved-file></code>
<code>$ git rm <resolved-file></code>
放棄工作目錄下的所有修改:
<code>$ git reset --hard head</code>
移除緩存區的所有檔案(i.e. 撤銷上次<code>git add</code>):
<code>$ git reset head</code>
放棄某個檔案的所有本地修改:
<code>$ git checkout head <file></code>
重置一個送出(通過建立一個截然不同的新送出)
<code>$ git revert <commit></code>
将head重置到指定的版本,并抛棄該版本之後的所有修改:
<code>$ git reset --hard <commit></code>
将head重置到上一次送出的版本,并将之後的修改标記為未添加到緩存區的修改:
<code>$ git reset <commit></code>
将head重置到上一次送出的版本,并保留未送出的本地修改:
<code>$ git reset --keep <commit></code>
<b>原文釋出時間為:2015-06-25</b>
<b></b>
<b>本文來自雲栖社群合作夥伴“linux中國”</b>