Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore continue to track file after adding it once by force

Tags:

git

gitignore

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?

like image 629
user1632167 Avatar asked Aug 30 '12 06:08

user1632167


People also ask

Should the .gitignore file be tracked?

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 .


2 Answers

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.

like image 124
Dominic Avatar answered Oct 15 '22 13:10

Dominic


You can remove it with...

git rm --cached file

Then commit.

like image 20
alex Avatar answered Oct 15 '22 12:10

alex