I'm wondering if there's a way to continue to track a particular file on a remote branch, but to have your local machine ignore any local changes you make to it (for example, a configuration file or something like that).
2 Answers
I use .template
files.
You can store Your configuration file with .template
suffix in repository and create local one without it (and add it to .gitignore)
For example, after You just cloned repo, You have
$ git clone my_repo
$ ls
myconfig.conf.template .gitignore
(and .gitignore contains myconfig.conf)
After clone, you should copy template file and You can edit config file and don't harm repo
$ cp myconfig.conf.template myconfig.conf
$ vim myconfig.conf

- 4,097
- 3
- 21
- 31
If you're not going to use .template
files, filters would come in handy. You would set up a smudge
filter that introduces your changes in the working copy and a clean
filter that is run before any git diff
or git add
.
The clean
filter would bring the file back into it's default state, the smudge
filter would modify the file as you want it to have.
I had similar needs some time ago and use filters since then (How to set a VSPROPS variable only if it does not already exist?).