第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將Git存儲庫還原為以前的提交

如何將Git存儲庫還原為以前的提交

Git
翻閱古今 2019-05-22 15:19:19
如何將Git存儲庫還原為以前的提交如何從當前狀態(tài)恢復為在某個提交時創(chuàng)建的快照?如果我這樣做git log,那么我得到以下輸出:$ git logcommit a867b4af366350be2e7c21b8de9cc6504678a61b`Author: Me <me@me.com>Date:   Thu Nov 4 18:59:41 2010 -0400blah blah blah...commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4Author: Me <me@me.com>Date:   Thu Nov 4 05:13:39 2010 -0400more blah blah blah...commit 0766c053c0ea2035e90f504928f8df3c9363b8bdAuthor: Me <me@me.com>Date:   Thu Nov 4 00:55:06 2010 -0400And yet more blah blah...commit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50Author: Me <me@me.com>Date:   Wed Nov 3 23:56:08 2010 -0400Yep, more blah blah.如何從11月3日恢復提交,即提交0d1d7fc?
查看完整描述

3 回答

?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

這很大程度上取決于“恢復”的含義。


暫時切換到其他提交

如果你想暫時回到它,傻瓜,然后回到你所在的位置,你所要做的就是檢查所需的提交:


# This will detach your HEAD, that is, leave you with no branch checked out:

git checkout 0d1d7fc32

或者,如果你想在那里做提交,那么在你做的時候繼續(xù)做一個新的分支:


git checkout -b old-state 0d1d7fc32

要回到原來的位置,只需查看您再次訪問的分支機構(gòu)。(如果你做了更改,就像轉(zhuǎn)換分支一樣,你必須在適當?shù)臅r候處理它們。你可以重置它們?nèi)拥羲鼈?你可以藏匿,結(jié)賬,存放pop以帶走它們;你可以提交如果你想在那里有一個分支,他們到那里的一個分支。)


硬刪除未發(fā)布的提交

另一方面,如果你想真正擺脫自那時以來所做的一切,那么有兩種可能性。一,如果您尚未發(fā)布任何這些提交,只需重置:


# This will destroy any local modifications.

# Don't do it if you have uncommitted work you want to keep.

git reset --hard 0d1d7fc32


# Alternatively, if there's work to keep:

git stash

git reset --hard 0d1d7fc32

git stash pop

# This saves the modifications, then reapplies that patch after resetting.

# You could get merge conflicts, if you've modified things which were

# changed since the commit you reset to.

如果你搞砸了,你已經(jīng)拋棄了你當?shù)氐淖兓?,但你至少可以通過再次重置來回到原來的位置。


使用新提交撤消已發(fā)布的提交

另一方面,如果您已發(fā)布作品,則可能不希望重置分支,因為這有效地重寫了歷史記錄。在這種情況下,您確實可以還原提交。使用Git,revert有一個非常具體的含義:使用反向補丁創(chuàng)建一個提交以取消它。這樣您就不會重寫任何歷史記錄。


# This will create three separate revert commits:

git revert a867b4af 25eee4ca 0766c053


# It also takes ranges. This will revert the last two commits:

git revert HEAD~2..HEAD


#Similarly, you can revert a range of commits using commit hashes:

git revert a867b4af..0766c053 


# Reverting a merge commit

git revert -m 1 <merge_commit_sha>


# To get just one, you could use `rebase -i` to squash them afterwards

# Or, you could do it manually (be sure to do this at top level of the repo)

# get your index and work tree into the desired state, without changing HEAD:

git checkout 0d1d7fc32 .


# Then commit. Be sure and write a good message describing what you just did

git commit

git-revert手冊頁實際上涵蓋在其描述中有很多這一點。另一個有用的鏈接是這個討論git-revert的git-scm.com部分。

如果您決定不想還原,則可以還原還原(如此處所述)或重置為還原之前(請參閱上一節(jié))。

在這種情況下,您可能還會發(fā)現(xiàn)此答案很有用:
如何將HEAD移回以前的位置?(獨立頭)


查看完整回答
反對 回復 2019-05-22
?
慕神8447489

TA貢獻1780條經(jīng)驗 獲得超1個贊

將工作副本還原為最近的提交

要恢復到先前的提交,請忽略任何更改:


git reset --hard HEAD

其中HEAD是當前分支中的最后一次提交


將工作副本還原為較舊的提交

要恢復到比最近提交更早的提交:


# Resets index to former commit; replace '56e05fced' with your commit code

git reset 56e05fced 


# Moves pointer back to previous HEAD

git reset --soft HEAD@{1}


git commit -m "Revert to 56e05fced"


# Updates working copy to reflect the new commit

git reset --hard

Credits轉(zhuǎn)到類似的Stack Overflow問題,在Git中恢復為SHA哈希的提交?。


查看完整回答
反對 回復 2019-05-22
?
holdtom

TA貢獻1805條經(jīng)驗 獲得超10個贊

我和其他人的最佳選擇是Git重置選項:

git reset --hard <commidId> && git clean -f

這對我來說是最好的選擇!它簡單,快速,有效!


注意: 如果您與擁有舊提交副本的其他人共享您的分支,則如評論中所述,請勿執(zhí)行此操作

同樣來自評論,如果你想要一個較少的'ballzy'方法,你可以使用

git clean -i


查看完整回答
反對 回復 2019-05-22
  • 3 回答
  • 0 關注
  • 865 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號