I have some partially generated file foo that I want to be checked in to the repository in an initial state but I don't want any changes to ever be noticed by git.
I thought putting it in the .gitignore
file and git add -f foo
would be enough, but git status
and git diff
show the changes in foo as well as git add .
adding it. Is there anyway I can do this?
Something like git update-index --assume-unchanged foo
but have it automatically for everyone, not just locally.
Hindsight edit: After dealing with similar problems to this for a while,
--skip-worktree
is preferable to--assume-unchanged
, see this question for why. The problem of magically making it apply to everyone still exists.
To be a little more specific it's some file that keeps track of an in-memory database for unit tests that needs the lines CREATE USER SA PASSWORD ""
and GRANT DBA TO SA
, if I delete this file when it gets regenerated those lines aren't there. It keeps track of the state of the database between runs which is why I don't want its changes to be checked into the repository.
I'm aware this is an odd case and that figuring out how to have it generated with those lines or not have it keep track of the state is probably a better solution.
Steps to reproduce
mkdir test
cd test
git init
echo "hey" > foo
git add .
git commit -m "Add hey to foo"
echo "foo" > .gitignore
git add .
git commit -m "Ignore foo"
echo "bye" > foo
git diff # will show foo's change
git status # will show foo has changed
git add . # will add foo's change to index