Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - merging into master always produces same conflicts even though fixed last time

Tags:

git

merge

Even though I fix the merge conflicts (keeping staging and removing HEAD), next time I merge from my staging branch into master, the same conflicts happen, even though the code that is described as HEAD no longer exists on HEAD as I removed it last time.

What I don't understand, if I choose to keep the code changes from staging and commit them to master, then why, if I have not kept the 'changes' on master do they show up again next time I merge staging in to master? How can code on staging conflict with code on master that isn't there?

like image 922
Jon Hudson Avatar asked Nov 28 '25 12:11

Jon Hudson


1 Answers

Presumably you have a situation where:

  1. There have been changes on master after the branch was made. These changes on master conflict with changes that have been made on the branch, and
  2. You want to keep the changes as they exist on master (or at least some of them). Thus, every time you merge your branch back in the same conflicts will occur despite resolving them last time.

You can use git rerere (reuse recorded resolution) which will record the resolution when you resolve the merge conflict, and reuse it when it detects the same conflict. To do this, run:

git config --global rerere.enabled true

The next time you get a merge conflict, you should notice a line that looks like Recorded preimage for '<filename>', and when you commit the conflict resolution you should see Recorded resolution for '<filename>'.

Then, the next time you merge your branch in, git should say something like Resolved '<filename>' using previous resolution and apply the same fix you made last time automatically.

like image 156
Adam H Avatar answered Nov 30 '25 05:11

Adam H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!