糟糕!好像我做錯了什麼最後一次我在倉庫合併兩個分支:在git中將雙親提交轉換爲單親提交
Original repository http://img532.imageshack.us/img532/9039/screenshotrm.png
這得從我所期待的遠。有沒有辦法安排這個混亂,並獲得像下面這樣的東西?我做錯了什麼?
What I am looking for http://img684.imageshack.us/img684/9977/screenshot2ah.png
糟糕!好像我做錯了什麼最後一次我在倉庫合併兩個分支:在git中將雙親提交轉換爲單親提交
Original repository http://img532.imageshack.us/img532/9039/screenshotrm.png
這得從我所期待的遠。有沒有辦法安排這個混亂,並獲得像下面這樣的東西?我做錯了什麼?
What I am looking for http://img684.imageshack.us/img684/9977/screenshot2ah.png
合併提交應該有兩個家長。這是合併的全部要點。
如果你有一個很好的理由爲希望合併只有一個家長,您可以使用--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
Imageshack不再提供屏幕截圖 – janv8000 2016-05-09 11:35:10
@ janv8000糟糕,這很不幸。我不再擁有屏幕截圖的副本,而互聯網Wayback Machine在這裏沒有太多幫助。儘管如此,這個問題的答案仍然很有趣。但謝謝你指出。 – Auron 2016-05-10 08:15:56