git revert和git reset的區(qū)別詳解
git revert和git reset的區(qū)別
git revert 是生成一個新的提交來撤銷某次提交,此次提交之前的commit都會被保留
git reset 是回到某次提交,提交及之前的commit都會被保留,但是此次之后的修改都會被退回到暫存區(qū)
具體一個例子,假設有三個commit, git st:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
當執(zhí)行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 沒有任何變化
如果換做執(zhí)行git reset --soft(默認) HEAD~1后,運行git log
commit2: add test2.c
commit1: add test1.c
運行git status, 則test3.c處于暫存區(qū),準備提交。
如果換做執(zhí)行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。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
linux shell之控制臺打印各種顏色字體和背景的實現(xiàn)方法
今天小編就為大家分享一篇關于linux shell之控制臺打印各種顏色字體和背景的實現(xiàn)方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-04-04
Shell腳本調(diào)試?-n?-v?-x?-c的具體用法
本文主要介紹了Shell腳本調(diào)試?-n?-v?-x?-c的具體用法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-06-06
linux定時備份MySQL數(shù)據(jù)庫并刪除以前的備份文件(推薦)
這篇文章主要介紹了linux定時備份MySQL數(shù)據(jù)庫并刪除以前的備份文件,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01

