14

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

11

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.
Sign up to request clarification or add additional context in comments.

2 Comments

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).
Note: Prior to the initial commit, there isn't a HEAD to reset to. In that case, git rm --cached -r . will unstage everything.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.