1

In my package, I have a Unit test runner that runs as a part of build. This runner generates a text file that lists Unit test coverage of all source files in my code.

This file gets changed usually with every single commit, and git almost always shows the conflicts whenever I merge/pull/pop from anywhere in this particular file.

Is there a way I can make git always select the version of file that is currently in my local repository for this particular file, as it represents usually the updated coverage.

I thought of removing this file altogether from the repository but it let's me see the code coverage with every commit which is really good.

Tim
  • 41,901
  • 18
  • 127
  • 145
sublime
  • 4,013
  • 9
  • 53
  • 92
  • possible duplicate of [Git choose merge strategy for specific files ("ours", "mine", "theirs")](http://stackoverflow.com/questions/16825849/git-choose-merge-strategy-for-specific-files-ours-mine-theirs) –  May 07 '14 at 02:25

3 Answers3

1

You can choose yours on a case-by-case basis using --ours.

Choose Git merge strategy for specific files ("ours", "mine", "theirs")

Additionally, you could create a post merge hook to checkout your version of the file each time which would automate this to some extent, depending on your workflow.

Community
  • 1
  • 1
seanmcl
  • 9,740
  • 3
  • 39
  • 45
0

You probably want to run git pull with -X ours, however, I don't recommend having these kinds of auto-generated files in a repository. I would rather use a checkout hook.

Tim
  • 41,901
  • 18
  • 127
  • 145
FelipeC
  • 9,123
  • 4
  • 44
  • 38
  • 1
    Unless I'm so caffeine-deprived I'm not even aware of it, this is very wrong. It will cause git's merge driver to resolve all conflicting *hunks* in the merge, in every file, by silently taking the local version. OP doesn't want conflict resolution at the hunk level, he wants it at the file level, and he wants this only for specific files, not all files. – jthill May 07 '14 at 13:24
0

Configure a trivial merge driver that ignores the incoming file completely:

git config merge.ours.driver true    # or even --global this one

and assign that merge driver to the build products you want preserved in .gitattributes:

echo path/to/build-report merge=ours >>.gitattributes
git add .gitattributes

(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.)

jthill
  • 55,082
  • 5
  • 77
  • 137