Undo “git add <dir>”?

neoneye picture neoneye · Jan 9, 2011 · Viewed 65.8k times · Source

I mistakenly added files using the command "git add dir". I have not yet run "git commit". Is there a way to remove this dir and everything contained within it from the commit?

I have tried git reset dir, but it didn't work. Apparently git reset file is the way to undo it. But I have so many files and so little time.

Answer

Aristotle Pagaltzis picture Aristotle Pagaltzis · Jan 9, 2011

To remove a directory and everything inside it from the index,

git rm --cached -r dir

The --cached switch makes git rm operate on the index only and not touch the working copy. The -r switch makes it recursive.