2014-03-05 107 views
2

我已經完成了五次提交,並且我想在推送它們之前將它們全部整合到一個提交中。出於某種原因,我決定嘗試以不同於我通常使用的方式來做這件事。git rebase吃了我的提交!爲我翻譯'git reflog'輸出?

FWIW:我試圖按照這裏的說明http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

我會在下面提出很多細節,但是您可能想跳到問題的底部,因爲我把git reflog的輸出放在這裏,因爲我懷疑這是什麼意思。

因此,這裏是我做的事 - 用我所有的變化犯我所做的:

git rebase -i HEAD~5 

,我提出了與文本編輯器,顯示提交和我,誤我現在認識到,改變了所有的第一列'pick'到'squash'的值。

然後我看到一條錯誤消息。令我慚愧的是,我不記得錯誤信息是怎麼說的,但我認爲它說了類似於「你沒有承諾使用」的東西。

在這一點上,我又回到了提示,當我嘗試重複:

git rebase -i HEAD~5 

我得到的消息:

It seems that there is already a rebase-merge directory, and 
I wonder if you are in the middle of another rebase. If that is the 
case, please try 
     git rebase (--continue | --abort | --skip) 
If that is not the case, please 
     rm -fr /home/foo/dev/bar/.git/rebase-merge 
and run me again. I am stopping in case you still have something 
valuable there. 

然後我讀這個答案https://stackoverflow.com/a/12163247/364088這表明這樣做:

git reset --soft HEAD^ 

我做到了這一點(我希望我沒有)。完成之後。

git status 

表現出了許多文件與提交的修改雖然

git diff 

顯示沒有變化。無論如何,我然後做了一個

git commit 

現在我已經失去了我的最後五個提交中的所有chnages!

git reflog 

顯示(這只是它的頂部):

3f80e4b [email protected]{0}: commit: Decorator demo added 
1888dd9 [email protected]{1}: reset: moving to HEAD^ 
7d6228e [email protected]{2}: checkout: moving from master to 7d6228eb9b03d0c45acf7c66e662220213cf4fb9 
705736f [email protected]{3}: commit: Snapshot commit - squash later 
75db0c3 [email protected]{4}: commit: Snapshot commit - squash later 
b70b50f [email protected]{5}: commit: Snapshot commit - squash later 
d970a62 [email protected]{6}: commit: Snapshot commit - squash later 
0f24e88 [email protected]{7}: commit: Snapshot commit - squash later 
7d6228e [email protected]{8}: commit: Move some standard code into its own module and tidy up . 
1888dd9 [email protected]{9}: commit: Early version of the decorators demo 

所以事情是標有「快照提交 - 南瓜後」的提交是我想合併一些分成單個提交。

提交HEAD @ {2}和HEAD @ {1}是我在嘗試合併這些「Snapshot commit - squash later」過程中所做的。提交HEAD @ {0}是我在rebase和reset之後做的提交。

如果重要,最後一次提交的操作是HEAD @ {8}。

所以我想回到'705736f'提交,然後,理想情況下再次合併提交只有這次才能使它工作!

如果我可以在「快照提交 - 壓扁後」更改中恢復工作,我會非常高興。

將不勝感激的意見。

回答

2

我的首選方法是粘在你要回來,像是一個分支的東西標籤:

git branch recover 705736f 

此時你可以檢查出來(這是一個新的本地分支),並確保你恢復你想要的東西:

git checkout recover 
git log # or gitk, or whatever 

這是一個新的分支標籤,在舊的(前底墊中,嘗試)指向提交。

你新的提交(Decorator demo added)將在其他分支,它(在圖形日誌查看器,像gitk --branchesgit log--graph)關閉後Early version of the decorators demo叉承諾。


如果你願意「吃虧」(除了在引用日誌)的新提交,你可以強制重置當前分支回老在引用日誌提交:

git reset --hard 705736f 

(而不是創建一個新分支指向705736f)。再次運行git log以查看這是否在您想要的位置(您甚至可以先用git log 705736f!)。

+0

謝謝我做到了這一點,它的工作。非常感謝。 – glaucon

1

只要做到:

$ git reset --hard [email protected]{3} 

,你會回來的地方你沒有上次提交的地步。從那時起你可以採取相應的行動

+1

感謝您的回答。在我嘗試@torek建議時,我沒有標記爲「正確」,因此我沒有機會嘗試您的建議。無論如何,我感謝你提供了一個答案,謝謝。 – glaucon

+0

這是行得通的,但不一定正確。您可以先通過調用'git reflog'來獲得正確的HEAD @ {#} –