創建
Git clone ssh://user@domain.com… 復制一個已創建的倉庫
Git init 常見一個新的本地倉庫
本地修改
git status 顯示工作路徑下全部已修改的文件
git diff 顯示與上次提交版本文件的不同
git add . 把當前所有修改添加到下次提交中
git add –p <file> 指定某個文件的修改添加到下次提交中
git commit –a 提交本地的所有修改
git commit 提交之前的已標記的變化
git commit – amend 修改上次提交(請勿修改已發布的提交記錄)
提交歷史
git 從最新提交開始顯示所有的提交記錄
git log –p<file> 顯示指定文件的所有修改
git blame <file> 誰,在什么時間,修改了文件的什么內容
分支與標簽
git branch –av 顯示所有分支
git checkout <branch> 切換當前分支
git branch <new-branch> 創建新分支(基于當前分支)
git checkout – track <remote/branch> 創建新的可追溯的分支(基于遠程分支)
git branch –d <branch> 刪除本地分支
git tag <tag-name> 給當前的提交打標簽
更新與發布
git remote –v 列出當前配置的遠程端
git remote show <remote> 顯示遠程斷信息
git remote add <shortname> <url> 添加新的遠程端
git fetch <remote> 下載遠程端的所有改動到本地(不會自動合并到當前)
git pull <remote> 下載遠程端的所有改動到本地(自動合并到當前)
git push <remote> <branch> 講本地版本發布到遠程端
git branch –dr <remote/branch> 刪除遠程端分支
git pushi -- tags 發布標簽
合并與重置
git merge <branch> 將分支合并到當前
git rebase <branch> 將當前版本重置到分支中(請勿重置已發布的提交!)
git rebase --abort 退出重置
git rebase --continue 解決沖突候繼續重置
git mergetool 使用配置好的合并工具去解決沖突
git add <resolved-file> (在編輯器中手動解決沖突后編輯文件為已解決沖突)
git rm <resolved-file> (在編輯器中手動解決沖突后編輯文件為已解決沖突)
撤銷
git reset –hard HEAD 放棄某個文件的所有本地修改
git checkout HEAD <file> 放棄某個文件的所有本地修改
git revert <commit> 重置一個提交(通過創建一個截然不同的新提交)
git reset <commit> --hard將HEAD重置到上一次提交的版本并拋棄該版本之后的所有修改
git reset <commit> 將HEAD重置到上一次提交的版本并將之后修改標記文未添加到緩存區的修改
git reset --keep<commit>將HEAD重置到上一次提交的版本并保留未提交的本地修改