简体   繁体   中英

Add a file to a git repository but ignore future changes on it

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM