Two Files Staged, Only One Belongs
git add eggs.md notes.txt
git status
Both are genuinely staged now. notes.txt was never meant to be part of any commit — it is a private scratch file, not a recipe.
Unstaging Without Losing Anything
git restore --staged notes.txt
notes.txt moves back to being untracked — its content is completely untouched, it is simply no longer queued for the next commit. eggs.md stays staged.
The Older Syntax, Doing the Same Thing
git add notes.txt # staged again, on purpose, to demonstrate
git reset HEAD notes.txt # the pre-2.23 way to unstage
Both commands genuinely produce the identical result. git restore --staged (introduced in Git 2.23, 2019) is the modern, clearer-named replacement — but you will still see git reset HEAD <file> in a lot of real tutorials and older codebases.
You are jotting a scrambled eggs recipe into eggs.md, and a genuinely private scratch file — notes.txt, a couple of personal reminders — happens to be sitting in the same folder. git add sweeps up both at once, and now notes.txt is staged for a commit it was never meant to be part of.
This is not a crisis. Staging is not committing — the staging area is a real, genuine waypoint, not a one-way door. git restore --staged moves a file back out of it, with every word of its content completely untouched.
git restore --staged <file>
Moves a file out of the staging area and back to being unstaged (or untracked, for a new file), without touching its actual content in any way. Confirmed directly in this lab: notes.txt's content was identical before staging it and after unstaging it.
git reset HEAD <file>
The older, pre-2.23 syntax for the exact same operation as git restore --staged. Confirmed directly in this lab producing an identical result. Still common in older tutorials and scripts, which is why recognizing it matters even though restore is the modern default.
Takeaways
- git restore --staged <file> moves a file out of the staging area without touching its content at all
- git reset HEAD <file> is the older syntax for the exact same operation — both are genuinely safe
- Staging is a real, separate waypoint between editing and committing — never a one-way door
- A file can be staged and unstaged as many times as needed before the actual commit happens