Git在先前合并的分支中合并

时间:2013-02-06 15:17:58

标签: git github

我遇到过某个分支在之前的某个时刻被合并到主分支并且分支的更改不再在master中的情况。可能这是因为合并冲突处理不当,但此时此刻我并不确定。

主分支中需要此先前合并的分支中的更改,但现在如果我尝试将分支合并到主Git中,则返回消息“已经是最新的”。因为此分支之前已合并。强制重新合并此分支的最佳方法是什么?

3 个答案:

答案 0 :(得分:2)

我认为这会做你的

mkdir alreadyapplied.patches
git format-patch -o alreadyapplied.patches master..alreadyapplied

然后

git checkout -b wip master
git am alreadapplied.patches
# (do whatever's necessary to deal with conflicts here)
# (rebase wip here if the conflict resolution has taken
# long enough that the wip branch has gotten behind master)
git checkout -B master wip
git branch -d wip    

答案 1 :(得分:0)

根据涉及的提交数量,您可以依次cherry-pick每个提交。

答案 2 :(得分:0)

另一种方法是在合并之前获取分支的提交ID,并将HEAD重置为指向它,然后您可以进行任何需要修复并将该分支重新合并为master

git reset (--hard/--soft/--mixed) _commit_ # where the _commit_ is the commit ID of the old branch
<work and make changes>
git commit -m "Made changes to commit before merging into master"
git checkout master 
git merge (--no-ff) otherBranch

重置您的HEAD将有效地让您了解该提交的内容。请注意,使用 - hard 选项可能会有危险,因为它具有破坏性,会使您的索引和工作区看起来与在提交阶段完全一样(您将失去其他工作) )。

相关问题