How to ignore existing, committed files in git?

Frank Nocke picture Frank Nocke · Jul 16, 2012 · Viewed 7.4k times · Source

Possible Duplicate:
GIT: Ignoring Version-Controlled Files

There are plenty of answers around .gitignore on Stackoverflow, still I haven't found an answer:

I have an existing git project, with a readme.md and a sample_folder/, both on top-level. I do want to remove these from my git(hub) repository in general. But I would like to ignore them, that is, preventing them to be pulled at all, in a certain cloned local repository, i.e. on a deployment machine.

.gitignore I understand, is only about ignoring non-committed files? Frankly, I don't find anything around hiding (from pull+commit) stuff that already is committed...

In the days of Perforce I would simple exclude it from the respective 'client spec' (which is pretty close to a locally cloned repo):

//whatever/myProject
-//whatever/myProject/readme.md
-//whatever/myProject/sample_folder

Sure, I could settle for a second branch where I simply delete readme and the entire sample folder. But then, I would have to keep merging over every tiny fix from 'develop'. Which is something, I would rather avoid... I'd rather prefer a local 'exception' over a (tracked) branch.

Also, I think git rm --cached whenever I do commits (which may also happen now and then from my 'deployment repo')...

Answer

thameera picture thameera · Jul 16, 2012

Perhaps I got the question wrong, but wouldn't the following solve your problem?

git rm --cached readme.md sample_folder/*
echo "readme.md" >>.gitignore
echo "sample_folder/*" >>.gitignore
git commit -am "Untracked some files"