1

I have file tst.properties that I would like not update from git remote repository. Also I would like not commit it to remote while not editing .gitignore. I don't want edit .gitignorebecause other team members don't follow defined constant tst.properties rule. How to protect this file from update from remote and not track changes before commit?

vico
  • 17,051
  • 45
  • 159
  • 315
  • 1
    Possible duplicate of [How do you make Git ignore files without using .gitignore?](http://stackoverflow.com/questions/653454/how-do-you-make-git-ignore-files-without-using-gitignore) – Julien Lopez Dec 15 '16 at 13:18
  • @JulienLopez this is not the right duplicate as OP wants to ignore changes to a tracked file incoming and outgoing – Vampire Dec 15 '16 at 13:30

1 Answers1

0

This is not possible, not even with editing .gitignore or one of its relatives. A tracked file is a tracked file is a tracked file. You cannot make Git ignore changes to a tracked file that come in from remote or changes you did locally. If a file is tracked it is tracked, fullstop.

You might read somewhere about --assume-unchanged to ignore local changes to a tracked file, but this is a dangerous option, as then Git thinks the file is always unchanged locally and will overwrite the file if you change branches or get in changes from remote, effectively loosing your local changes as for Git there are no local changes.

The right technique is to delete tst.properties from the repository and add it to .gitignore, adding a file tst.properties.sample that people can copy locally to tst.properties and modify to suit their needs, or to add a second layer of files, so that in tst.properties the defaults are defined and tracked and you can have a second file tst-local.properties that is in .gitignore and can be used to overwrite settings from tst.properties. For the latter option the software that evaluates the file has to be changed to support this of course.

Vampire
  • 35,631
  • 4
  • 76
  • 102