您好,登錄后才能下訂單哦!
這篇文章主要介紹了git的revert和reset有哪些區(qū)別的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇git的revert和reset有哪些區(qū)別文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。
git revert和git reset的區(qū)別
git revert 是生成一個(gè)新的提交來(lái)撤銷(xiāo)某次提交,此次提交之前的commit都會(huì)被保留
git reset 是回到某次提交,提交及之前的commit都會(huì)被保留,但是此次之后的修改都會(huì)被退回到暫存區(qū)
具體一個(gè)例子,假設(shè)有三個(gè)commit, git st:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
當(dāng)執(zhí)行g(shù)it revert HEAD~1時(shí), commit2被撤銷(xiāo)了
git log可以看到:
revert "commit2":this reverts commit 5fe21s2...
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
git status 沒(méi)有任何變化
如果換做執(zhí)行g(shù)it reset --soft(默認(rèn)) HEAD~1后,運(yùn)行g(shù)it log
commit2: add test2.c
commit1: add test1.c
運(yùn)行g(shù)it status, 則test3.c處于暫存區(qū),準(zhǔn)備提交。
如果換做執(zhí)行g(shù)it reset --hard HEAD~1后,
顯示:HEAD is now at commit2,運(yùn)行g(shù)it log
commit2: add test2.c
commit1: add test1.c
運(yùn)行g(shù)it st, 沒(méi)有任何變化
另外:
git revert <commit log string>是撤消該commit,作為一個(gè)新的commit。
關(guān)于“git的revert和reset有哪些區(qū)別”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“git的revert和reset有哪些區(qū)別”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。