简体   繁体   中英

Git : Merge a branch again after a revert

Please consider this git tree :

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. There was a branch called feat, from dev, and it was merged back into dev after a few commits. 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. 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. And all of that has been pushed to origin. This is the H commit.

What i did locally is git revert HEAD , which gave me the I commit to undo the H commit. 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.

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.

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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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