0

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).

Mason
  • 6,893
  • 15
  • 71
  • 115
  • what about conflicts ? – Zaffy Apr 07 '14 at 13:48
  • 1
    It needs some research, but you can ignore changes in local files via .gitignore and .git/info/exclude. Not sure how conflicts would be solved when you add tracked file there. – samuil Apr 07 '14 at 13:51

2 Answers2

3

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
Arenim
  • 4,097
  • 3
  • 21
  • 31
2

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?).

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201