Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using gitignore to ignore (but not delete) files

I have a tmp directory in my git repo I'd like to still exist, but be ignored. I added it to .gitignore, but git status still tells me about changes to files in that directory. I tried git rm -r --cached, but that removes it from the remote repo. How can I stop tracking changes to this directory, but still allow it to exist? I also need to do this for 1 file, but changes to that also show up in git status after .gitignoreing them. What should I do?

like image 965
21312312 Avatar asked Jun 11 '11 16:06

21312312


People also ask

Does Gitignore delete files?

You basically remove and re-add all files, but git add will ignore the ones in . gitignore . Using the --cached option will keep files in your filesystem, so you won't be removing files from your disk.

How do I ignore a file without adding to Gitignore?

To ignore untracked files, you have a file in your git folder called . git/info/exclude . This file is your own gitignore inside your local git folder, which means is not going to be committed or shared with anyone else. You can basically edit this file and stop tracking any (untracked) file.


1 Answers

Instead of .gitignore, you can update local git repository by running following command:

git update-index --assume-unchanged <file> 

In this case a file is being tracked in the origin repo. You can modify it in your local repo and git will never mark it as changed. Read more at:

  • http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ - was reported dead at some time (sorry, not mine)
  • http://archive.robwilkerson.org/2010/03/02/git-tip-ignore-changes-to-tracked-files/ - another one covering the same topic
like image 114
ducin Avatar answered Sep 27 '22 18:09

ducin