2011-07-16 116 views
39

我試圖修復git的問題,不小心使用的git的復位 - 硬一些以前的承諾。所以現在我無法回到老頭上。的Git失去了承諾

但是我沒有克隆庫我這樣做之前,所以我把丟失的承諾回到原來的。這似乎昨天工作,但今天我看到,原來仍然停留在舊的承諾,新的似乎並不存在。 試圖從克隆推新提交的git的告訴我一切再次不工作是最新的。

我該如何解決這個問題?

回答

58

爲了讓你的後腦勺在正確的地方:

  1. git reflog獲得的,其中頭部有一直最近的列表。
  2. git show sha1找到你想要你的頭爲光斑。
  3. 一旦你找到你想要的提交,git merge讓你的主人回到正確的位置。

一些解釋:在一個git提交沒有任何指向一個提交後發生的提交。當您重置HEAD時,您將其指向較舊的提交。你以前的頭現在晃來晃去沒有任何指向它。

我們使用reflog來查看HEAD最近在哪裏。一旦它回到你想要的位置,你將主人或其他一些分支指向那個地方,一切都很好!

+2

'git cherry-pick the sha1's' –

-8

嘗試鍵入git fetch獲得更新的資料庫

24

我做得有點不同。我沒有...

git reflog 
3bd79d2 [email protected]{2}: checkout: moving from edbfb06528c43586a0e0e10a73051e06980b9281 to master 
edbfb06 [email protected]{3}: commit: added general comments for rubric 
f8ca172 [email protected]{4}: checkout: moving from 904d63bf08f6f6b1494bfa473b158b9509b18423 to 
904d63b [email protected]{10}: commit: updated results page and csv 
933f2a6 [email protected]{11}: commit: updates 
f56e6cd [email protected]{12}: clone: from [email protected]:xxxx.git 

......在這種情況下,我的「爲欄目增加一般性意見」是承諾,我失去了。現在我有了提交ID,我用cherry-pick取回它...

git cherry-pick edbfb06