简体   繁体   中英

Redo wrong merge in GIT

Long time ago in the git history I can see that someone did a wrong merge of two branches. He had a conflict, so he simply deleted a lot of the conflicted changes. The result is that the main branch doesn't contain these changes (and we didn't even suspect it until we checked).

Branch feature was merged into branch development . Feature contains changes XY Z. However, Y and Z were deleted during the merge, so development only contains X. I want to merge feature into development again, because I need all changes. However, GIT thinks that they are already merged (it knows that they conflicted and were manually "resolved").

How can I do this merge?

Some notes:

  • I cannot simply merge, the changes are not visible at all.
  • I cannot cherry-pick, it doesn't work.
  • I don't want to "just copy the files and commit them again" because that would mean that GIT failed in a crucial use-case
  • I tried using different git merging strategies with partial success, but each strategy leaves out some files and in the end I don't have all the changes in development

Of course merging feature into a new branch (that starts from a development commit, just before the wrong commit) works. I can see all necessary changes. But again, I can't merge this new branch into development due to the reasons above.

Have a look at the git book section on how to undo merges: https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_undoing_merges

It recommends using git revert to undo the merge commit. And to solve the problem of re-merging (as git complains that those commits are already in the history) it recomments reverting the revert (instead of trying to merge again).

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