3

This question is very similar to: How do I tell git to always select my local version for conflicted merges on a specific file? with an important difference.

I have followed the excellent steps in VonC's answer to the above question and everything almost works. However, in my situation I only have changes to the incoming version of the file (not both the local and incoming version).

No merge is really necessary since only one branch has changes. In this case it appears that git does not bother to run the merge driver and simply overwrites the local version with the incoming one, which is exactly what my custom merge driver was supposed to prevent.

Is there any way to essentially tell git that it should never change a particular file during a merge (even under the circumstances described above where VonC's answer appears not to quite work)?

Community
  • 1
  • 1
ulmangt
  • 5,343
  • 3
  • 23
  • 36

1 Answers1

2

It seems other have tried and failed to force a conflict when Git decides there is none.

This SO question "Git merge - manual merge - forcing conflic having WHOLE old and new file version" concludes in the comments:

What I am most afraid is that answer: "it's not possible, cause it's the way git works".

And "Need GIT workflow suggestion" mentions trying:

*.xml merge=Unset into my .gitattributes file.
Or a custom merge driver into ~/.gitconfig trying to cause the auto-merge to fail

In other words, that might not be the right approach.

If you are certain that all the modifications introduced by your merge shouldn't be here, then you can try:

git clone yourRepo aCloneRepo
cd aCloneRepo
git merge --no-commit --no-ff origin/source_branch
# simply overwrite any change file by the ones in ..\yourRepo
git add .
git commit -m "merge"

Note that the final "git merge" will work even though your git status mentions there is nothing to commit (since you restore the content of all modified files).
It will record the merge in a new commit.

That will give you:

C:\Users\VonC\prog\git\tests\mergekeep\r4>git lg
*   a6a1588 - (HEAD, master) merge (2 minutes ago) <VonC>
|\
| * 1bcd75d - (origin/b) addition (2 hours ago) <VonC>
|/
* 9d2e8fb - (origin/master, origin/HEAD) first file (2 hours ago) <VonC>

But with local files unchanged.

And if you try again to merge your branch, you will get:

C:\Users\VonC\prog\git\tests\mergekeep\r4>git merge origin/b
Already up-to-date.

However, that workaround is cumbersome, involves a clone and some manual copy or rsynch from one working tree to another.
I tried to play with various git reset commands or plumbing commands like git update-index, but without much success.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I've convinced myself that there's no really clean answer and simply adjusted my workflow and repository to avoid the issue... Much thanks for the comprehensive answer and for the workaround suggestions. – ulmangt Jul 16 '12 at 19:44