How to Undo a Git Add Before Commit
Scenario A: You Have Commits Previously
1
$ git reset <file>
or equivalently
1
$ git reset HEAD <file>
The above command will:
- Remove the file from the current index (the “about to be committed” list) without changing anything else
1
$ git reset
The above command will:
- Remove all files from the current index. This is handy if there are too many files to be listed one by one.
Scenario B: You Do Not Have Any Commits Yet (A New Repository)
1
$ git rm --cached <file>
The above command will:
- Remove (unstage) the file from the current index.
1
$ git rm -r --cached .
The above command will:
- Remove all files from the current index.