13

I've accidentally staged a lot of changes including new files that I do not want to commit.

How can I unstage or reset only the new files?

I am not looking for a script of any kind; I am looking for core git functionality to be exposed and documented here on SO under a meaningful topic title.

0

1 Answer 1

9

One way you may be able to do this is to unstage / reset everything and then re-stage only what you wanted:

git reset HEAD ./
git add -u
# -u stages changes to tracked files, and will not stage new files.
2
  • That's pretty much the way. Note that this is a reset --mixed and can be spelled git reset --mixed HEAD -- ., which makes explicit that you're asking to move HEAD to HEAD with a path-name of .. Moving HEAD to HEAD is itself a no-op, so only the index-reset part (via --mixed) has any effect, and the path specified is ., the current directory (all its files, and any sub-directories and their files, recursively).
    – torek
    Commented Jun 24, 2014 at 19:26
  • 2
    Note: Prior to the initial commit, there isn't a HEAD to reset to. In that case, git rm --cached -r . will unstage everything. Commented Jun 24, 2014 at 19:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.