0

In our git repository there is, say, settings.ini that contains a bunch of configuration data. When I test our program locally, the program automatically changes some values in the file such as local directory paths or IP address, etc, which are of no interest to anyone upstream, but of course the owner of the settings module might add new settings that I need to download.

Currently, we use the Gitflow pattern, so I work on a feature, but then when I try to do git flow feature finish my_feature I get an error:

Fatal: Working tree contains unstaged changes. Aborting.

Of course, git checkout -- settings.ini or git stash gets me around this, but is there a way to mark a file as "ignore local changes" so I can stop getting the error and keep my changes?

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • Once a file is tracked git won't ignore it (afaik), so the usual "work around" is to keep a `.local` version which isn't tracked and is ignored. Once you pull/merge whatever, replace `settings.ini` with `settings.ini.local` – evolutionxbox Jul 24 '18 at 08:43

1 Answers1

1

Have a look at this blog post here:

https://www.jimbobbennett.io/hiding-api-keys-from-git/

This has a technique for "hiding" information from git, which basically entails adding the file as you would want it to be checked into the repository, then run the command:

git update-index --assume-unchanged ./<your file name here>

This will tell git to ignore any future changes to the file.

Obviously, as noted in the article, if you do want to actually make changes to the file you will need to update the file again.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60