2

At first, I know this question How do I tell git to always select my local version for conflicted merges on a specific file? but this post doesn't help me and I can't add any comments because of my reputation.

http://git-scm.com/book/en/Customizing-Git-Git-Attributes suggests to set the merge strategy to ours for the path instead of setting a custom merge driver.

What is the benefit and differene of adding a custom merge driver return an exit code 0?

I have a .gitattributes file on my repos top level:

pom.xml merge=ours

But when I merge two branches with changed pom.xml files the merge can't be resolved:

$ git merge origin/master
Auto-merging pom.xml
CONFLICT (content): Merge conflict in pom.xml
Automatic merge failed; fix conflicts and then commit the result.

And I get a standard merge conflict result:

<pom>
<<<<<<< HEAD
    <version>0.88-SNAPSHOT</version>
=======
    <version>0.87.0</version>
>>>>>>> origin/master
</pom>

What am I doing wrong?

Community
  • 1
  • 1
BlackEye
  • 775
  • 11
  • 25

1 Answers1

3

You can declare a merge driver, but that means you have to define it on the git config, as in ".gitattributes & individual merge strategy for a file":

[merge "ours"]
    name = "Keep ours merge"
    driver = true

That allows for a merge strategy for a file, or set of files, as opposed to the -s option for git merge strategies, which doesn't require you to define a driver, but which would resolve the conflict for all files (not just for pom.xml)

git merge -s ours
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The problem is we are using Atlassian Stash as our enterprise git repository so we can't specify any parameters for the merge. The next problem is, I don't know any option to provide the pull request with the merge driver :/ I'm awaiting a reply from Atlassian for this topic. – BlackEye Mar 25 '14 at 08:53
  • @BlackEye but if you define a merge driver, Stash would pick it up, as it reads the `.gitattributes` of your repo. – VonC Mar 25 '14 at 09:36
  • I'm not sure but I think Stash uses a temporary repository to merge the pull request. How should such a repository know the merge driver? – BlackEye Mar 25 '14 at 15:27
  • @BlackEye (assuming it does the merge on your workstation) it will see your .gitattributes, since it is a file from your repo. But it will know of the dirver only if it is defined in the global option (`git config --global ...`), because the temporary repo wouldn't see the local config of your local repo. – VonC Mar 25 '14 at 16:19
  • Stash is a web application, a frontend to git remotes according to this it manages bare repositories. Entries from a bare repository's .git/config are not inherited to cloned repositories, so I don't see any option to provide a config for the temporary repository :/ – BlackEye Mar 25 '14 at 16:59
  • 1
    @BlackEye it would be easy enough to convince your Stash admin to declare in a global config on the Stash server your merge driver, though. – VonC Mar 25 '14 at 17:52