5

We have a .NET solution file with 50+ projects in it, and we have a situation that comes up every so often: two people will make a relatively minor change (such as updating a Nuget package or renaming a file) that affects all 50 project files.

This means that any time those branches are merged all 50 of those files will be conflicted - but if you open them in just about any merge tool it will be able to resolve them automatically. This means that there's no actual work for me to do in the merge, but I have to click every file, wait for it to open in Beyond Compare, then click save, then click close. Click next file, click save, click close... repeat 55 times.

My question is this: is there any way that I can make Git, when faced with conflicted files, attempt to resolve them automatically using your merge tool?

Update: Hopefully this will add some clarity: I'm having to resolve each conflict one by one, but since my merge tool can resolve each one automatically, isn't there some kind of batch operation or option for the merge command that I can call?

Richiban
  • 5,569
  • 3
  • 30
  • 42
  • Since project files are simply MSBuild files, have you considered using [MSBuild Imports](http://msdn.microsoft.com/en-us/library/92x05xfs.aspx)? – Dark Falcon Feb 28 '14 at 14:00
  • I found this for you http://blogs.atlassian.com/2013/05/git-automatic-merges-with-server-side-hooks-for-the-win/ – abnvp Feb 28 '14 at 14:20
  • Thanks for the post abhinav, but that's not what I'm looking for either. Their post deals with automatically conducting merges on a push, but I'm talking about automatically resolving conflicts where possible on a local merge. – Richiban Feb 28 '14 at 14:25
  • @Richiban git *does* try to automerge your files for you, so it would be useful to know why it's failing and why Beyond Compare can do the merge. Do you have Beyond Compare set up to ignore whitespace? Do your teammates check in whitespace changes? Do they switch between line endings? Do they disagree on settings for `core.autocrlf` = true? – Edward Thomson Feb 28 '14 at 17:41
  • 1
    Thanks @EdwardThomson, I've since discovered that after doing an experiment on a new Git repo, but I don't know why it wasn't done in this case... I think it must have been combined with some whitespace changes to cause the conflict, and although Beyond Compare was fine with that, Git raised it as a conflict (probably correctly). – Richiban Mar 03 '14 at 09:44

3 Answers3

0

Your merge tool 'Beyond Compare' is using some merge strategy for displaying the differences and result side-by-side. Determine what merge strategy that tool is employing and then find the equivalent strategy in GIT. See git help merge for the available strategies and their options.

By default, GIT uses the 'recursive' strategy. As a quick check, you might employ the 'resolve' strategy and see if you get the resolution you desire.

git merge -s resolve ...

or, using the 'recursive' strategy with a likely option or two, such as:

git merge [-s recursive] -X ignore-all-space

Once you've identified the desired strategy you can set it as the default using configuration variables or with a command alias.

GoZoner
  • 67,920
  • 20
  • 95
  • 145
0

I had the same problem some time ago. After many searches, I found a one and two solutions.

Put this in $HOME/.gitconfig:

[merge]
    ff = no
    commit = no

You can use git-config to do this:

$ git config --global merge.commit no
$ git config --global merge.ff no

Now, when you will merge branches, git automatically merge the code using the 'recursive' strategy

$ git merge master
Auto-merging Dockerfile
hint: Waiting for your editor to close the file...
Merge branch 'master' into feature/ea-116
Merge made by the 'recursive' strategy.
 Dockerfile        | 63 +++++++++++----------------------------------------------------
 1 file changed, 129 insertions(+), 59 deletions(-)
...
Serhii Popov
  • 3,326
  • 2
  • 25
  • 36
-1

You can set a mergetool for git when there is a conflict that cannot be resolved automatically by git. please take a look at:

git-mergetool

Daniel
  • 20,420
  • 10
  • 92
  • 149
  • Sorry if I misunderstand, but I don't think you read my question. I have a merge tool configured already - but I'm having to resolve each conflict one by one when my merge tool can resolve each one automatically. – Richiban Feb 28 '14 at 14:14
  • @Richiban You can use git mergetool in a way that it does not prompt you for each conflict, from the link: `-y` `--no-prompt` `Don't prompt before each invocation of the merge resolution program.` – Daniel Mar 03 '14 at 08:45