I have some tracked files in a repository which are automatically modified when building the code. I don't want to untrack them, I just don't want them to appear as modified and I don't want them to be staged when I git add.
Is this possible?
Join Stack Overflow to learn, share knowledge, and build your career.
I have some tracked files in a repository which are automatically modified when building the code. I don't want to untrack them, I just don't want them to appear as modified and I don't want them to be staged when I git add.
Is this possible?
Sure.
git update-index --assume-unchanged [<file> ...]
To undo and start tracking again:
git update-index --no-assume-unchanged [<file> ...]
Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.
– Parham
Sep 2 '14 at 12:33
--assume-unchanged
upon cloning? So that all users would have the files, but not see local changes to them in diffs.
– Gauthier
Apr 24 '15 at 8:33
git update-index --no-assume-unchanged $(git ls-files $(git rev-parse --show-toplevel))
set as an a git alias. Whenever I suspect it's some of these shenanigans I just do that.
– Philippe Carphin
Feb 13 '19 at 22:17
An another solution using git attributes and %f in filter command:
git config filter.orig.clean "cat %f.orig"
cp filename filename.orig
echo "filename filter=orig" >> .git/info/attributes
echo "filename.orig" >> .git/info/exclude
Another approach (from a now deleted answer by Seth Robertson, but I found it helpful so resurrecting it) is to maintain a "tracked" template file, then have local untracked version of it, ex: "config.sample.ini" or "config.ini.template" see https://gist.github.com/canton7/1423106 for a full example.
Then there won't be any concerns if the file is changed within git, etc. and you can use .gitignore (finally) on the local untracked files.