Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git says Automatic merge failed but when i check the file or run the mergetool there are no conflicts they were resolved correctly

As stated in the description. I would like to not even be prompted to resolve merge conflicts when they were automatically resolved.

My Scenario is that I add a line containing a fixed text string to a text file on one branch, do some other commits on that same branch, then on another branch cherry-pick the change which adds the fixed text, then do a merge with the other branch.

I'm doing this as a test because in my day-to-day i often get conflicts but when i use my merge tool it says there are no conflicts so i just close it and commit manually.

The issue is that i'm prompted for extra steps when in reality git already merged in the changes correctly. (I even checked the file manually to make sure it wasn't my merge tool doing the resolution and indeed the conflict is already resolved int the file).

I tried using the "--commit" parameter to git merge but it has no effect.

It seems like git fails in automatically merging the changes according to the message but in reality it actually merged the files correctly.

Is there a way to just auto merge these kinds of conflicts and continue without manual intervention?

I'm using git version 1.7.10.msysgit.1

like image 823
Coder Avatar asked Nov 13 '22 03:11

Coder


1 Answers

This might not answer your question, but if you know what you are merging, you can make it so that you don't need to resolve conflicts at all, depending on what you are merging, by giving it a strategy (and options). Non fast forward merges are usually done by the recursive strategy, which is good, but you can give it an option too.

If you merge using

$ git merge branchB --strategy=recursive -Xours

Then every conflict you would have normally, is instead automatically resolved with your lines. This would probably work in your situation, when you know you shouldn't be getting conflicts, but are getting them anyway. Like I said, this automatically resolves conflicts with your version, so use it only when you know in advance that your version is what is needed.

A more safe option that automatically fixes any conflicts relating to whitespace is ignore-all-space. So:

$ git merge branchB --strategy=recursive -Xignore-all-space

I recommend this one, because it is very safe, it may help your case, and it saves a lot of cases where the to-be-merged file has the entire contents split to local and remote, which would make resolving conflicts very difficult.

like image 138
Attila Szeremi Avatar answered Nov 16 '22 01:11

Attila Szeremi