John Doe
John Doe

Reputation:

Ignore modified (but not committed) files in git?

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

The situation is that I have a subdirectory 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?)

Upvotes: 220

Views: 106831

Answers (6)

David L
David L

Reputation: 44657

A newer and better option is git update-index --skip-worktree which won't be lost on a hard reset or a new change from a pull.

See the man page.

And a comparison at http://fallengamer.livejournal.com/93321.html

Upvotes: 42

csmosx
csmosx

Reputation: 3381

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

Upvotes: 323

Walter
Walter

Reputation: 7981

What I usually do is

git stash

git whatever-else

git stash apply

git stash clear

Upvotes: 7

Gabriel Arghire
Gabriel Arghire

Reputation: 2360

What worked in my case:

git restore --staged filename

Example: git restore --staged index.js

Upvotes: 0

Sujiraj R
Sujiraj R

Reputation: 1642

Use this code

git update-index --assume-unchanged file-name

Upvotes: 15

John Feminella
John Feminella

Reputation: 311446

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.

Upvotes: 7

Related Questions