Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Git merge conflicts where HEAD + commit are identical

I just ran a git pull origin master and many of the merge conflicts are identical in HEAD and the upstream commit:

<<<<<<< HEAD
gem 'fuzzy-string-match'
=======
gem 'fuzzy-string-match'
>>>>>>> 50147a3519be5bc883dabce86525ee4f36640b22

There are dozens of files with the same situation, where the before and after are identical.

Does anyone know what might cause this behavior? Or if there’s a way to auto-merge these "conflicts"?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is because u have 2 head sections git doesn’t know wich one is the right one that’s why he shows u where conflicts are. Best way is to work with comments so he knows the difference when u merge.

Resolving merge conflicts automatically
In cases when you prefer the work of other developers rather than yours, you can mention the appropriate strategy to resolve the conflicts by giving the preference to other developers’ work.

git pull -s recursive -X theirs <remoterepo or other repo>

Or, simply, for the default repository:

git pull -X theirs

If you have already pulled without using the theirs strategy and want to give the preference to the work of other developers in one of the conflicting files, then run the command below:

git checkout --theirs path/to/file

If you are already in a conflicted state and want to give the preference to the work of other developers in all the conflicting files, then run the git checkout and git add commands:

git checkout --theirs .
git add .

If you give the preference to the code, written by yourself, then you should use –ours , instead of –theirs as follows:

git checkout --ours .
git add .

However, this is drastic, so make sure before running it.

You may not use the "." and type the file name in place of the dot to checkout.

You can also use the recursive –theirs strategy option with git merge:

git merge --strategy-option theirs
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading