created on | June 22, 2022 |
last modified on | June 28, 2022 |
Changes that have been staged yet with , can be removed from the index with . To undo unstaged changes for a specific file, run:
Or, for the whole working dir:
Restore a specific file:
Restore the whole working directory
Changes that have been staged (with ), can unstaged with . To unstage a file that has been staged, run:
To unstage all changes that have been staged, run:
Prior to git version 1.8.2 you had to add the pointer to to unstage a file that has been staged (with ):
and for all changes that have been staged:
The problem with was that if you worked with a new repo and did not have made any commit to your repo, would fail because without any commit there would be no HEAD pointer. Thus, the behaviour of was changed to allow unstaging changes in a repo without any prior commit.
An alternative is using , for single files, run:
to restore the whole directory, use
or