一, 查看:git
git status # 查看有變動的文件 git log # 顯示當前分支的版本歷史 git log --stat # 顯示commit歷史,以及每次commit發生變動的文件 git diff # 顯示暫存區和工做區的代碼差別 git blame [file] # 顯示指定文件是什麼人在什麼時間修改過 git show [commit] # 顯示某次提交的元數據和內容變化
git branch
# 列出全部本地分支
git branch -r
# 查看全部遠程分支
git branch -a # 查看全部分支
二, 增長 建立分支 並提交到遠程分支:bash
git branch -r # 查看全部遠程分支 git branch -a # 查看全部分支 git checkout branch-name
# 新建一個分支可是依然停留在當前分支
git checkout -b branch-name
# 新建一個分支,而且切換到該分支
git branch --track[branch-name][remote-branch-name]
# 新建一個分支與指定的遠程分支創建追蹤關係
git branch --set-upstream [branch] [remote-branch]
# 創建追蹤關係,在現有分支與指定的遠程分支之間
git merge [branch]
# 合併指定分支到當前分支
三, 刪除:spa
git branch -d [branch-name] # 刪除分支 git push origin --delete [branch-name] git branch -dr [remote/branch] # 刪除遠程分支 1 git branch -r -d origin/branch-name git push origin :branch-name 刪除遠程分支 2
四, 代碼回滾:指針
git checkout [file] # 恢復暫存區的指定文件到工做區 git checkout [commit] [file] # 恢復某個commit的指定文件到暫存區和工做區 git checkout . # 恢復暫存區的全部文件到工做區 git reset [file] # 重置暫存區的指定文件,與上一次commit保持一致,但工做區不變 git reset --hard # 重置暫存區與工做區,與上一次commit保持一致 git reset [commit] # 重置當前分支的指針爲指定commit,同時重置暫存區,但工做區不變 git reset --hard [commit] # 重置當前分支的HEAD爲指定commit,同時重置暫存區和工做區,與指定 commit一致 git reset --keep [commit] # 重置當前HEAD爲指定commit,但保持暫存區和工做區不變 git revert [commit] # 新建一個commit,用來撤銷指定commit # 後者的全部變化都將被前者抵消,而且應用到當前分支 git stash git stash pop # 暫時將未提交的變化移除,稍後再移入 git archive # 生成一個可供發佈的壓縮包 git reset --hard version-num # 回滾到指定版本 git revert HEAD 撤銷前一次 commit git revert HEAD^ 撤銷前前一次 commit git revert fa042ce57 撤銷指定的版本,撤銷也會做爲一次提交進行保存。