简体   繁体   English

Git:还原后再次合并分支

[英]Git : Merge a branch again after a revert

Please consider this git tree : 请考虑以下git树:

local repo:
          C---D---E       feat
         /         \
    A---B---F---G---H---I dev

origin remote repo:
          C---D---E   feat
         /         \
    A---B---F---G---H dev

We have a git repo with an origin remote. 我们有一个git repo,带有一个远程的源。 There was a branch called feat, from dev, and it was merged back into dev after a few commits. 有一个来自dev的分支,称为feat,在提交几次后便合并回dev。 The problem is that the feat branch provided a lot of modifications to the dev branch, and came with lots of conflicts, so we decided that feat source code should prevail, and used the -X option when merging. 问题在于feat分支对dev分支进行了很多修改,并带来许多冲突,因此我们决定以feat源代码为准,并在合并时使用-X选项。 We checked the result too quickly, and pushed on the remote. 我们过快地检查了结果,然后将其推到遥控器上。 But we made a mistake, we used -Xours instead of -Xtheirs when merging so all conflicts were automatically resolved using dev branch code, not feat branch code. 但是我们犯了一个错误,在合并时使用-Xours而不是-Xtheirs ,因此所有冲突都是使用dev分支代码而不是feat分支代码自动解决的。 And all of that has been pushed to origin. 所有这些都被推到了起源。 This is the H commit. 这是H提交。

What i did locally is git revert HEAD , which gave me the I commit to undo the H commit. 我在当地所做的是git revert HEAD ,这给了我承诺撤消为H提交。 From there i tried to merge the feat branch again, with the right -Xtheirs option and git tells me the tree is already up to date, but modifications from feat branch aren't present in the source code. 从那里,我尝试再次合并feat分支,使用正确的-Xtheirs选项,并且git告诉我树已经是最新的,但是feat分支中的修改未出现在源代码中。

I tried to branch from feat, a rescue branch, and merge that into dev, but it did the same. 我试图从一个壮举,一个救援分支中分支出来,然后将其合并到开发人员中,但是它做了同样的事情。 I tried to commit some small changes on feat branch, and merge into dev, but only the small modifications go into dev. 我尝试在feat分支上进行一些小的更改,然后合并到dev中,但是只有这些小的更改才进入dev。

So here's my question : How can i get back the work done in feat branch into dev? 所以这是我的问题:我如何才能将专长分支中完成的工作恢复为开发人员?

I would just take dev back in time and retry the merge: 我只是想让开发人员回到过去,然后重试合并:

git checkout dev
git reset --hard G # provide sha1 of the revision of G... and use with care, you know what they say of git reset hard
git merge -Xtheirs feat # this is what you wanted to do, right?
git push origin -f dev # set remote dev to have the rewritten history of local dev

Git allows you to rewrite history. Git允许您重写历史记录。 If has implications (revisions are completely different so you are effectively diverging.... if other people are already working on the old branch, then they will have to move their work on top of the new branch an so on... still, it's possible). 如果有影响(修订版本完全不同,因此您实际上是在分歧。...如果其他人已经在旧分支上工作,那么他们将不得不将工作移到新分支之上,依此类推...这是可能的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM