35

I want to add an overrides.json. That allows developers to make changes to a config object locally. I want it added to the repository in a default state but I want future changes on it to be ignored.

It seems like .gitignore forces me to remove it from the branch before I can ignore it. I know about git update-index but each developer would have to do this manually. To clarify, I do not want the file removed; I actually want the file to be added to repository but untracked after that.

I can't simply remove it because GET requests to a missing file throws ugly error messages in the browser's javascript console.

Brennan Cheung
  • 4,271
  • 4
  • 30
  • 29
  • 1
    couldn't you make the file read only and then commit it ? – saruftw Nov 10 '14 at 23:00
  • 1
    No, I want developers to change it locally. This would be for enabling dev type features but keeping them out of the production config. – Brennan Cheung Nov 10 '14 at 23:09
  • possible duplicate of [Git ignore local changes to tracked files](http://stackoverflow.com/questions/21756531/git-ignore-local-changes-to-tracked-files) – 1615903 Nov 11 '14 at 12:55
  • see this answer for similar solutions http://stackoverflow.com/questions/4348590/how-can-i-make-git-ignore-future-revisions-to-a-file – Aaron Hoffman Jul 03 '15 at 20:19
  • Possible duplicate of [How can I make git ignore future revisions to a file?](https://stackoverflow.com/questions/4348590/how-can-i-make-git-ignore-future-revisions-to-a-file) – rofrol Nov 17 '17 at 09:24

2 Answers2

41

After adding the file you can ignore all further changes by doing:

git update-index --assume-unchanged path/to/file

If at some point you decide that you need to push more changes you can allow again changes by doing:

git update-index --no-assume-unchanged path/to/file

Instead of adding the files in the repo, why not ignore them and add them to a different location, eg. a setup directory. This way after cloning the repo, the developers will need to execute an init step that will copy the needed files in the proper location, where they are ignored.

dan
  • 13,132
  • 3
  • 38
  • 49
  • 1
    As I stated earlier, this requires the developers to do this manually. I can't "`push`" this `--assumed-unchanged` to the repository. I'm worried that developers will just do `git add .` and their changes will get pushed into the repository. – Brennan Cheung Nov 10 '14 at 23:17
  • @BrennanCheung No, unfortunately I don't know a good way to propagate the `assume-unchanged` flag. But see my updated answer for a workaround. – dan Nov 10 '14 at 23:59
3

Ignore it and don't add it to the repo. Instead, generate a default version by the project's makefile if it does not exist. Assuming of course that you have a makefile, or any kind of make or build process.

SzG
  • 12,333
  • 4
  • 28
  • 41
  • This sounds like it would work but it's not ideal. If I was going to do that I might as well use the Rails style (development|test|production) sections in the config file. However, this is an AngularJS app and has no server component other than nginx so I would have to make a custom build process and do it at that time. It's a possible solution but way overboard if I can find a solution within git. – Brennan Cheung Nov 10 '14 at 23:08
  • Is AngularJS able to create the file on the client side? – SzG Nov 10 '14 at 23:11