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?
If unwanted files were added to the staging area but not yet committed, then a simple reset will do the job: $ git reset HEAD file # Or everything $ git reset HEAD . To only remove unstaged changes in the current working directory, use: git checkout -- .
What Does Git Add Do? git add [filename] selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit.
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
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 #
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With