0

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?

LeonardChallis
  • 7,759
  • 6
  • 45
  • 76

1 Answers1

2

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.

Community
  • 1
  • 1
jwg
  • 5,547
  • 3
  • 43
  • 57
  • Basically I want a specific version of the file to be part of the repository so when people clone it they see the file, but then when a change is made (and committed) it can be ignored on a specific machine – LeonardChallis Jun 09 '14 at 13:49
  • OK I basically want to do what that answer says is impossible :P Thanks for the information – LeonardChallis Jun 09 '14 at 13:52
  • 1
    You probably want a slightly tweaked combination of local config files which never get checked in and general config files which have conditional sections or something equivalent... – jwg Jun 09 '14 at 13:53