git revert回滾操作實例

##分別進行四次提交
wangjunjie@z0410200075 MINGW64 /e/test/test (master)
$ git log --oneline
6732512 this is fourth change
b08208d third change
e559822 second commit
a5808f7 create test file

##回滾到前兩次之前提交(e559822... second commit)
wangjunjie@z0410200075 MINGW64 /e/test/test (master)
$ git revert HEAD~2
error: could not revert e559822... second commit
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

##因為改的同一份文件,產生沖突
wangjunjie@z0410200075 MINGW64 /e/test/test (master|REVERTING)
$ git status
On branch master
You are currently reverting commit e559822.
  (fix conflicts and run "git revert --continue")
  (use "git revert --abort" to cancel the revert operation)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        both modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")
##進入沖突文件解決沖突
wangjunjie@z0410200075 MINGW64 /e/test/test (master|REVERTING)
$ vi test.txt
##解決完沖突后,加入緩存
wangjunjie@z0410200075 MINGW64 /e/test/test (master|REVERTING)
$ git add -A
##提交,回滾完成
wangjunjie@z0410200075 MINGW64 /e/test/test (master|REVERTING)
$ git commit -m 'solutiong confilic'
[master 12be922] solutiong confilic
 1 file changed, 1 insertion(+), 3 deletions(-)

wangjunjie@z0410200075 MINGW64 /e/test/test (master)
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容