27

I have special branch (release branch) which is an exact copy of master branch with some files and directories removed. No development is happening on this branch, however it must be in sync with master, so updates on master must be constantly pushed to that branch.

By doing a normal merge (git merge master) I constantly get conflicts like (a sample README file for example):

CONFLICT (delete/modify): README deleted in HEAD and modified in master

which is expected: I try to merge changes in files, that I've deleted. So, to resolve them I jut use git rm README.

To automate it, I though I could use automatic conflict resolution by specifying -X ours. Man pages suggest it is a right thing for me:

This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree that do not conflict with our side are reflected to the merge result.

However, when I do git merge -s recursive -X ours master I still get the same unresolved delete/modify conflicts. What am I doing wrong? Is there another way to automate conflict resolution?

  • possible duplicate of [How to setup a git driver to ignore a folder on merge](http://stackoverflow.com/questions/3111515/how-to-setup-a-git-driver-to-ignore-a-folder-on-merge) - and that has a great answer. – rescdsk Feb 17 '15 at 20:30

4 Answers4

23

There's probably a better way to do this, but I solved a similar problem by doing the merge (with the default merge strategy) and then running

git status | grep 'deleted by us' | awk '{print $4}' | xargs git rm

After this, you should resolve other conflicts as normal and then commit.

This just deletes all files that had been deleted on the current branch, which I think is what you want.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Bryan Head
  • 12,360
  • 5
  • 32
  • 50
9
git merge master
git status --porcelain | awk '{if ($1=="DU") print $2}' | xargs git rm
git commit
fnkr
  • 9,428
  • 6
  • 54
  • 61
3

By having a look at this question, it looks like the recursive strategy with ours or their option doesn't consider a deletion as a conflict.

What you can do though is use this feature to specify a specific strategy for some files. I would bet that the ours strategy (not option) would do the trick for those files.

EDIT:

As stated in the comment, you can't do this !

You should definitly contact Git mailing list if this is a very important feature to you (git@vger.kernel.org)

Community
  • 1
  • 1
Antoine Pelisse
  • 12,871
  • 4
  • 34
  • 34
  • Seems like it could be the solution, but doesn't work for me (or I'm doing something wrong again): in the branch created and committed .gitattribute file with contents "README merge=ours". When I do `git merge master` same conflict appears – Vladimir Minakov Jul 04 '12 at 16:09
  • 1
    Tried creating a .gitignore file too and puting `README` in it. Same result – Vladimir Minakov Jul 04 '12 at 16:24
  • 1
    Maybe, custom merge driver is the thing I need? http://stackoverflow.com/questions/928646/how-do-i-tell-git-to-always-select-my-local-version-for-conflicted-merges-on-a-s – Vladimir Minakov Jul 05 '12 at 11:15
  • Oh yes, that's what I was going to test when I was interrupted yesterday – Antoine Pelisse Jul 05 '12 at 11:16
  • 3
    Actually it doesn't work, the merge driver isn't even called, that's why no strategy handle it correctly – Antoine Pelisse Jul 05 '12 at 17:08
-2

You can use rebase instead of merge to actualize release branch.

anton0xf
  • 51
  • 6