Reputation: 96827
Let's say I have a file named a.txt
. I add it to the staging area, and then I modify it. How could I return it to the way it was when I added it?
Upvotes: 97
Views: 32451
Reputation: 37
git restore --staged filename
This is the command to unstage a file after adding it.
Upvotes: 0
Reputation: 72828
git checkout a.txt
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
Upvotes: 101
Reputation: 2119
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
#
Upvotes: 32