When I want to unstage a staged file, all of my Git tutorials show something like:
$ git add *
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README
modified: CONTRIBUTING.md
This hint tells us to use git reset
for unstaging a staged file.
But instead, in my terminal, I see:
git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: cat.js -> catcat.js
renamed: tolendo.gogo -> tolendo.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
readme (copy).md
tolendo (copy).txt
zing (copy).html
My terminal tells me to use git restore --staged
but the tutorials, as well as Git’s website, tell me to use git reset HEAD
.
I have no idea about the new restore
command. I tried Google to find the difference between git reset
and git restore
but nothing seemed to fit my question.
I have presented
git restore
(which is still marked as "experimental") in "How to reset all files from working directory but not from staging area?", with the recent Git 2.23 (August 2019).It helps separate
git checkout
into two commands:git restore
), which can covergit reset
cases.git switch
, as seen in "Confused by git checkout"), which deals only with branches, not files.As reset, restore and revert documentation states:
So:
With Git 2.25.1 (Feb. 2020), "
git restore --staged
" did not correctly update the cache-tree structure, resulting in bogus trees to be written afterwards, which has been corrected.See discussion.
See commit e701bab (08 Jan 2020) by Jeff King (
peff
).(Merged by Junio C Hamano --
gitster
-- in commit 09e393d, 22 Jan 2020)With Git 2.27 (Q2 2020), "
git restore --staged --worktree
" now defaults to take the contents out of "HEAD", instead of erring out.See commit 088018e (05 May 2020) by Eric Sunshine (
sunshineco
).(Merged by Junio C Hamano --
gitster
-- in commit 4c2941a, 08 May 2020)So now, this works: