views:

2180

answers:

3

Can i tell git to ignore files that are modified (deleted) but should not be committed?

The situation is that i have a subdir in the repo which contains stuff I'm not interested in at all, so I deleted it to prevent it showing up in auto-completions and the like (in the IDE).

But now, if I add that folder to .gitignore, simply nothing changes, all the stuff is shown as deleted by git status.

Is there a way to make git ignore it either way?

(Alternatively, as I'm using git-svn, could I commit the changes to the local git and ensure they are not passed on to the svn repo?)

+5  A: 

Tracked files can't be ignored, so you'll have to remove them from your index first. Add a .gitignore that ignores the directories you don't want, then delete them, and remove any stragglers with git rm --cached.

John Feminella
Hm, I try this, but then i have all files listed as deleted. Should I commit that and the --cached will cause that it will not be pushed to remotes? Or did I get sth. wrong? The most important for me is not corrupting the remote (svn) repo.
You can't commit anything that doesn't start out in your index. git rm --cached everything that you don't want to commit, then add a .gitignore file locally that has "*" in it. Now, no matter how much you git add, you'll never see those files in your index again.
John Feminella
Ah, I think i understand --cached now.. It only removes the stuff from the index, and leaves the working tree alone.. I'm not sure whether I'm missing something, but AFAIS I'm looking for the opposite, removing it from the working tree without touching the index.. Or can I use it for that somehow?
A: 

What I usually do is

git stash

git whatever-else

git stash apply

git stash clear

Walter
+17  A: 

check out the git-update-index man page and the --assume-unchanged bit and related.

when I have your problem I do this

git update-index --assume-unchanged dir-im-removing/

or a specific file

git update-index --assume-unchanged config/database.yml
csmosx
This works great for modified files. However when I delete the dir (either with 'rm' or 'git rm') the files are listed as missing/deleted in 'git status'. I think I'll accept this as an answer and restate the question explicitly asking about deleted files.(At first, I didn't know that there was such a big difference ;)Thanks!
Awesome. This is exactly what I needed to ignore files that were already in the repo, but modified.
Pistos
Can you list all your ignored files somehow ?
Zitrax