Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tell git to use ours merge strategy on specific files

Tags:

I have the following directory structure:

/.git /.git/info/attributes /MyProject /MyProject/pom.xml /MyProject/MyCode.java 

I have branch master and bugfix. On both branches pom.xml and MyCode.java were modified. i would like to merge changes from bugfix to master only for MyCode.java and keep master version of pom.xml file.

So I added "/.git/info/attributes" because i don't want to commit .gitattributes with the project

$cat .git/info/attributes pom.xml merge=ours $git status # On branch master nothing to commit (working directory clean) $git check-attr -a pom.xml pom.xml: merge: ours 

Finally to the problem:

When I do:

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

Git is ignoring attributes setting. What am i missing here?

I prefer not to define "keepMine.sh" per this post

this post is what i need, however i prefer not to go file by file if i have a simple pattern

thanks!

like image 415
Barak1731475 Avatar asked Dec 30 '12 18:12

Barak1731475


People also ask

What does Git merge ours do?

git merge -s ours. The ours strategy is simple: it discards all changes from the other branch. This leaves the content on your branch unchanged, and when you next merge from the other branch, Git will only consider changes made from this point forward.


1 Answers

$ git config merge.ours.driver true 

or even

$ git config --global merge.ours.driver true 

'ours' isn't one of the built-in merge drivers even though it's perfectly clear to you and me what it should do, and it seems git doesn't error out when a custom merge driver is undefined.

(true above is just the unix true command, its success says it made the local version look right, in this case by doing nothing to it.)

like image 196
jthill Avatar answered Sep 27 '22 19:09

jthill