How do you revert a git file to its staging area version?
Solution 1:
- Prior to Git 2.23:
git checkout a.txt
- Starting from Git 2.23:
git restore a.txt
Git tells you this if you type git status
.
Prior to Git 2.23:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: a
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: a
#
Starting from Git 2.23:
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: a
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a
Solution 2:
git checkout -- a.txt
The other answer on this page doesn't have the --
, and resulted in some confusion.
This is what Git tells you when you type git status
:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: a
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: a
#