How to unadd a file#

It is a very common practice to quickly add all the files that were modified to staging using:

$ git add .

As you are about to commit, you may realize one or more files should be excluded from this commit, and you shouldn't have done git add ..

How do you "unadd" (unstage) these files now?

It's very simple to unadd them from staging, just use get reset HEAD <file1[, file2 ...]>.

For example:

$ git reset HEAD README.md

Now when you commit the changes, the unstaged files will be excluded from the commit.

Watch out for that git add . next time!

In case you want to undo the whole add command ("unadd" all the files), just do this:

$ git reset HEAD .

Summary#

To unadd one or more files from staging use the command git reset HEAD <file1[, file2 ...]>.

References#

  1. Git - git-reset
Tweet this | Share on LinkedIn |