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.

ThorSummoner
  • 16,657
  • 15
  • 135
  • 147

1 Answers1

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.
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
  • 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 Jun 24 '14 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. – Jonathan Lonowski Jun 24 '14 at 19:28