Git: reload conflicting commit

After finishing work on the topic branch, I merged the topic branch into a wizard, as shown below:

o---*---o---o topic / \ o---o---o---*---o---o---+ master 

The end marked with "*" changed the same code, so merging leads to merging conflicts that were resolved during compilation with commit (marked with a "+" sign).

While I combined and resolved the conflicts, my colleague pushed new commits to the master (marked as "n"), which led to the following story:

  o---*---o---o topic / \ o---o---o---*---o---o---+ master \ n---n origin/master 

Now clicking on my local branch of the wizard, of course, leads to an error, since this is not a fast-forward, so I have two options:

  • Drop my job, reset master to origin / master and retry the merge. I would like to avoid this, as I would have to resolve conflicts again.

  • Restore the master to the beginning / master and press. This is where my problem arises: performing this permutation (even when using the -p switch) does not work smoothly, the merge transaction shows the same conflicts again, even if the new commits ('n') did not change anything that affected the topic. Therefore, I would have to resolve conflicts again during rebase and have the same result as with parameter 1.

What I would like to achieve is reloading the + merge without resolving conflicts again:

  o---*---o---o-------- topic / \ o---o---o---*---o---o---n---n---+ master & origin/master 

Edit:

The reer switch is on, but it doesn't help; do i need to do something more than set config.rerere to true to fix my problem?

Edit 2:

Combining merge-commit ('+') at the beginning / wizard will also work (as suggested in the comments and answer), but will lead to some ugly story that I would like to avoid having only one merge.

+8
source share
4 answers

The first way would be the best. Cancel your merge and repeat it to make a colleague change the commit merge. But you do not need to discard the changes.

Since you know that the changes of your colleagues did not affect the files in which you resolved the conflicts. You can create a new branch (we will call it conflict-fix ) from your current state of the wizard. Reset your branch and merge again.

Instead of using git mergetool or any other editor you use. You can transfer the file to the master from another branch using git checkout conflict-fix -- <file names> . git add files and commit to complete the merge. Then you can remove the conflict-fix branch.

This is fairly easy to do and will result in the only team pool you are looking for and allows you to modify your changes. If the new commits affected the files that you resolved, conflicts in them would need to be redone again.

EDIT

I am not completely familiar with git rerere , but this should work. However, based on your comment, you do not need to reinstall. You would still undo merge commit, git fetch updates, and merge re-execution. You just need to call the git rerere and it will resolve file conflicts for you. With your tree it looks like this:

  o---*---o---A topic / \ o---o---o---*---o---o---+ master \ n---n origin/master 

You would do the following:

 git reset --hard A git checkout master git pull git merge topic git rerere //Fix other conflicts git push 

And you should end up with:

  o---*---o---o-------- topic / \ o---o---o---*---o---o---n---n---+ master & origin/master 

No need to reinstall anything.

http://git-scm.com/docs/git-rerere

+1
source

What to do if you reinstall the theme on top of the wizard, then reset the wizard to the previous commit and pull it out of the remote so that you have this:

  o---*---o---o / \ o---o---o---*---o---o---+ topic \ n---n master & origin/master 

And then you merge the theme into master, resulting in this (a new merge commit is marked as "#"):

  o---*---o----o / \ o---o---o---*---o---o----+ topic \ \ n--n--# master 

Does it cause conflicts? Will this work for you?

0
source

rerere is a way to avoid such a fuss, but if you did not turn it on before you did the first merge, it will not help you. You can know if it is turned on, because it will give messages about the "prototype of the record"

I came across this myself recently, because I had a new development machine and forgot to turn on the re-merger before the ugly merger. There is no big git solution for this scenario, but the following is the easiest way to restore this situation in which I could come up with.

  • Make sure your working directory is the exact result of the merge (git reset HEAD --hard) and copy the source tree from your merge in a safe place
  • reset your local branch back before all merged commits (git reset --hard master ~ or git reset HEAD ~ n, where n is how far back you need to go)
  • git pull
  • git merge theme
  • copy the source files back to your working tree.
  • git mergetool (to handle any deleted or modified conflicts)
  • commit and click

Since we worked with gerrit, I also made sure that Change-Id was the same as my previous merge, so I could verify that nothing happened.

0
source

As far as I read / understood about rerere he will be able to help in this particular situation if you use the rerere-train.sh script to record rerere-train.sh solutions already.

So the following should do the trick:

  1. Run the script using args <merge commit>^..<current branch> β†’ now rerere knows exactly about your conflict resolution / merge only
  2. Make sure you have rerere.enabled=true in your configuration
  3. Execute option 1 (repeat merging with the updated wizard, see Question) β†’ now rerere should be able to reuse previously recorded permissions
  4. With rerere.enabled , you can rerere.enabled again (there may be reasons not to leave it turned on, see are there any flaws in enabling git rerere? )

If you do not want to use the script, you can also do manual training, see fooobar.com/questions/435944 / ...


Update :

Keep in mind that with rerere only conflict / resolution records for conflict blocks (with <<<< and >>>> in it). It will not record the resolution of conflicts arising from deletion in one branch and changes in another branch for the same file. In addition, it does not record any additional changes that you have made outside the conflict.

You have one more option , although it is not very popular, especially if origin/master was published to an unknown circle of people: rebase origin/master on the local master and make a forced push.

I chose this option several times in the past, not necessarily based on the same situation, but with other cases where it was desirable to rewrite the history of origin/master . If you have a small team, it's just a matter of communication / coordination.

0
source

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


All Articles