Reputation: 25133
I have a file with database settings in my project which I have set to some defaults. The file is tracked by Git
and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Git
to ignore new changes to this file?
I tried adding the file to the .gitignore
file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
Upvotes: 25
Views: 12345
Reputation: 9086
One may use git update-index --skip-worktree FILE
for this purpose.
It is similar to --assume-unchanged
but, unlike --assume-unchanged
, is not just an unpredictable performance trick.
To cancel --skip-worktree
effects and unset the flag use --no-skip-worktree
.
git pull
. (more details)Upvotes: 23
Reputation: 53563
I recommend naming the source-controlled file differently than its actual expected name. For example, if the file is normally named config.json
, then name your example file config.json.dist
and commit this file. Then add config.json
to your .gitignore
file. Your devs would simply cp config.json.dist config.json
after cloning, and then edit it as required, making subsequent commits without having to worry about accidentally changing the default file or forgetting to toggle some setting on and off all the time.
You might even edit your code to search for config.json
first, and if that doesn't exist, fall back to config.json.dist
. This would allow the devs to work without even performing the copy step. (This is how PHPUnit works.)
Upvotes: 19
Reputation: 309
You can use git update-index --assume-unchanged <file>
And if you want to track it again use git update-index --no-assume-unchanged <file>
Upvotes: 3