2010-05-26 34 views
4

糟糕!好像我做錯了什麼最後一次我在倉庫合併兩個分支:在git中將雙親提交轉換爲單親提交

Original repository http://img532.imageshack.us/img532/9039/screenshotrm.png

這得從我所期待的遠。有沒有辦法安排這個混亂,並獲得像下面這樣的東西?我做錯了什麼?

What I am looking for http://img684.imageshack.us/img684/9977/screenshot2ah.png

+0

Imageshack不再提供屏幕截圖 – janv8000 2016-05-09 11:35:10

+1

@ janv8000糟糕,這很不幸。我不再擁有屏幕截圖的副本,而互聯網Wayback Machine在這裏沒有太多幫助。儘管如此,這個問題的答案仍然很有趣。但謝謝你指出。 – Auron 2016-05-10 08:15:56

回答

11

合併提交應該有兩個家長。這是合併的全部要點。

如果你有一個很好的理由爲希望合併只有一個家長,您可以使用--squash選項:

# starting with branch-full-reordering at "Corrected GPU float measures" 
git merge --squash branch-full-reordering-wo-auxarray-wo-diver 
# go on to make the "improve performance commit" 

但是這是非常,非常罕見你想要什麼。它將在其他分支上完成的所有工作轉儲到合併提交中,從而破壞歷史記錄。

但是,您描述的歷史根本不是合併,也不是壁球。這是一個rebase。

# starting with branch-full-reordering at "Corrected GPU float measures" 
git rebase branch-full-reordering branch-full-reordering-wo-auxarray-wo-diver 
# go on to make the "improve performance commit" 

在這種情況下將不會有合併提交 - 你只是移植(衍合)次支路到主之一。

我應該再次強調:你最終的歷史可能是你想要的。它記錄的事實,一些發展發生在一個側枝的地方,然後合併回去

要修改你的歷史,看你想要的方式,你可以做這樣的事情:

# recreate your topic branch 
git branch topic <SHA1 of commit "Correct pesky bug"> 
# overkill: you could also specify that as branch-full-reordering^^2 
# which means the second parent of the [first] parent of the branch tip 

# rebase the topic branch like you meant to in the first place :) 
# ~2 means two commits before 
# you could also just use the SHA1 of commit "Corrected GPU float measures" 
git rebase branch-full-reordering~2 topic 

# rebase the main branch onto the topic 
# the merge will be ignored, so this will just move the "Improve performance" commit  
git rebase topic branch-full-reordering 

# delete the topic branch 
git branch -d topic 
+0

是的,也許我一直在尋找的是一個真正的變形而不是合併。對不起,我在git錯綜複雜中有點新手。但是它做了什麼,它完成了。我可以將庫的當前狀態更改爲第二張圖嗎? – Auron 2010-05-26 14:52:52

+0

@Auron:是的,絕對。你可以做任何事情!我將在一些說明中進行編輯。 – Cascabel 2010-05-26 14:53:51

+0

我試過重新裝訂,但比我原先想象的要複雜。我想我會離開這兩個分支,因爲正如你所說,這反映了我開發這兩個分支的方式更好。謝謝! – Auron 2010-05-27 14:01:45