git revert和git reset的區別
阿新 • • 發佈:2018-12-17
原文:http://blog.csdn.net/koffuxu/article/details/6731876
git revert
是生成一個新的提交來撤銷某次提交,此次提交之前的commit都會被保留
git reset
是回到某次提交,提交及之前的commit都會被保留,但是此次之後的修改都會被退回到暫存區
具體一個例子,假設有三個commit, git st:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
當執行
git revert
HEAD~1時, commit2被撤銷了
git log可以看到:
revert "commit2":this reverts commit 5fe21s2...
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c git status 沒有任何變化 如果換做執行 git reset --soft(預設)
HEAD~1後,執行git log
commit2: add test2.c
commit1: add test1.c
執行git status, 則test3.c處於暫存區,準備提交。
如果換做執行
git reset --hard HEAD~1後,
顯示:HEAD is now at commit2,執行git log
commit2: add test2.c
commit1: add test1.c
執行git st, 沒有任何變化
另外:
git revert <commit log string> 是撤消該commit,作為一個新的commit。
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c git status 沒有任何變化 如果換做執行 git reset --soft(預設)
再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!希望你也加入到我們人工智慧的隊伍中來!http://www.captainbed.net