我有一個非常具體的案例與Git,我需要幫助通過。幾個星期前,一個有重大改變的分支合併爲主,現在它需要消失。但是,我們不想失去一些其他承諾,與其他分支無關。Git:恢復分支合併並保存在該頂部的提交
我們如何刪除分支合併並重新應用其他提交在新HEAD上?
我有一個非常具體的案例與Git,我需要幫助通過。幾個星期前,一個有重大改變的分支合併爲主,現在它需要消失。但是,我們不想失去一些其他承諾,與其他分支無關。Git:恢復分支合併並保存在該頂部的提交
我們如何刪除分支合併並重新應用其他提交在新HEAD上?
最好的方法是使用git revert
來恢復合併。
git help revert
說:
-m parent-number, --mainline parent-number
Usually you cannot revert a merge because you do not know which side of the
merge should be considered the mainline. This option specifies the parent
number (starting from 1) of the mainline and allows revert to reverse the
change relative to the specified parent.
Reverting a merge commit declares that you will never want the tree changes
brought in by the merge. As a result, later merges will only bring in tree
changes introduced by commits that are not ancestors of the previously
reverted merge. This may or may not be what you want.
See the revert-a-faulty-merge How-To[1] for more details.
如果你真的想改變歷史,除去從歷史上的合併,你是真正意識到造成的一切後果,你可以使用git rebase
這樣做:
git rebase --onto $good_commit $merge_commit branch
,而merge_commit
是錯誤的合併提交,並且其已知好的父項。
請注意,在這兩種情況下,如果較新的提交更改了合併提交引入的代碼,則可能很難這樣做。
請注意,還原合併提交不會撤消合併。它只解除了合併提交引入的更改。該分支仍被視爲合併,因此未來的合併嘗試似乎失敗,因爲不會有未合併的更改。 –
用你所描述的,聽起來好像alteration_branch的所有變化都在master上。正常情況下,如果您不提供強制選項,刪除git branch -d alteration_branch
的分支將不會刪除歷史記錄。我建議試着刪除它。
就個人而言,我想創建一對夫婦開始在分裂的兩個(基)點(一個用於舊的分支,以及一個主上只是在合併之前)臨時分支。我會在master的頂端創建兩個分支,然後在這兩個臨時基本拆分分支上交互rebase'master'(實際上是這兩個tip分支),以通過從rebase todo列表中選擇正確的提交來創建所需的順序。請記住,包括跨合併發生的任何變化(檢查重訂選項合併默認忽略)
現在你應該有兩個新的,獨立的,發展的,代表你想要的結果行。如果沒有,重複該過程。
最後,在推送更新並宣佈每天必須執行強制拉動(永不重寫歷史日)之前,強制更新主分支和分支的兩個分支參考(例如git update-ref
)
這可能是你想要什麼http://stackoverflow.com/a/6217372/167614 –