Merge Hiding

I have a problem that just came up with my colleague and I am wondering how best to work with git for this problem.

Let's say we have two branches A and B. Now we change some file ( foo.c ) in both A and B, so we get a merge conflict when we merge B into A. Now let's say that some the developer messed up and left branch A in a broken state, and the error is also in foo.c, but in a line that has not been merged.

I see some possibilities for handling this situation:

  • Fix the pending merge, fix the problem on A, commit and apply the merge again. However, at the moment I'm not sure how to handle the right merge strategy for the changes that both made to foo.c. The broken part may affect some of the things I did, and therefore I don’t see a clear way to resolve conflicts.

  • Cancel the merge, fix the problem on A, and then retry the whole merge. However, I may have already resolved other conflicts, so this can lose a lot of work.

  • Take our version of the file --theirs / - our version, go through a merge, fix the changes, cherries select the losses that were lost. However, then I will have some changes twice.

  • Some other solution that I cannot think of.

All these solutions seem a little unsatisfactory to me. In my usual experience, I will probably go with 1, but I'm absolutely not sure about that.

How would you handle this situation?

+4
source share
1 answer

You cannot hide an uncommitted merge. Option 1 is immediately disconnected from the list.

For pure history, option 2 is better. Git has the ability to remember conflict resolution; it is disabled by default. You can enable it: git config --global rerere.enabled . Resolve conflicts if necessary. Normally, you should do a merge, and Git will record a way to resolve conflicts. Since you really don't want to merge, you can simply run git rerere to immediately record conflict resolution without committing. (Alternatively, if you went ahead and merged, you could just git reset --hard HEAD^ , rebooting to it. The resolution of the conflict is still remembered.)

Then you can fix the problem in branch A and repeat the merge. Git will re use re conflict conflict re . It will still be marked as unrelated, so you will have the opportunity to review it and make sure that it did the right thing before running git add on unlinked tracks and fixing the merge.

And I do not quite understand option 3. Why do you need a cherry pick? It seems that foo.c only breaks into branch A, into which you merge, so it will all be in branch A. The desired story is a mistake, followed by a merge; if you continue and merge instead, then fix the problem, you just switch the order of the two commits. In any case, it is not necessary to have recurring commits - I can help avoid this if you clarify!

+3
source

Source: https://habr.com/ru/post/1382728/


All Articles