I have a file mentioned in .gitignore, but I added it by git add -f
because I wanted to add
it only once and then ignore it as usual.
However, it is now tracked by default. How do I undo this?
Yes, you can track the . gitignore file, but you do not have to. The main reason of having this file into repository is to have everyone working on the project, ignoring same files and folders. Also see this: Should you commit .
Not completely sure what you're looking for but you can either remove the file to be ignored in future commits with
git rm --cached filename
Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm --cached filename
Info: https://help.github.com/articles/ignoring-files
Or you can tell git that it ignores the changes of a file with
git update-index --assume-unchanged filename
and undo it with
git update-index --no-assume-unchanged filename
To list all assume-unchanged files run
git ls-files -v|grep '^h'
Info: How do I .gitignore and delete an already committed file without affecting other working copies?
However please keep in mind that assume-unchanged is (in my opinion) against the philosophy of git and this command will only ignore it the changes made on your machine. Everyone else will still be able to overwrite it.
In most cases you use this for configuration files. What you can do to avoid using this option is to keep it in the .gitignore and add a setup description to the README or create a little setup script which creates those files.
You can remove it with...
git rm --cached file
Then commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With