Why is my Git ours merge strategy being ignored?

426 views Asked by At

I want to ignore a certain file from being overwritten regardless of whether there are changes. I have the following in /etc/gitconfig:

[merge "ours"]
        driver = true

And in the repository itself, in .git/info/attributes:

files/somefile.txt merge=ours

However, when I run git pull, the somefile.txt file is being overwritten regardless. Have I got this configured wrongly, or is there something I'm not understanding properly?

1

There are 1 answers

3
jwg On BEST ANSWER

The merge=ours only applies if a merge is actually needed, ie there have been changes to the file on both sides. It won't protect a file from any remote updates if it hasn't been modified locally. If this is the case, git simply checks out in a normal way. It never start doing a merge of the file, and so never even looks at the merge strategy.

See this answer: https://stackoverflow.com/a/22085876/1737957

Should you be using the ignore list instead to keep a local version of the file? This is what you should use if the file is different on every machine, or changes to it never need to be shared.