Unstage A File
Part of the Version Control section of Coddy's Terminal journey — lesson 41 of 58.
If you accidentally staged a file you did not mean to include in the next commit, you can unstage it with:
git restore --staged secrets.txtThe --staged flag tells git restore to modify the staging area instead of the working directory. The file's actual content is left alone; only its staged state is reset.
After unstaging, git status shows the file as modified-but-not-staged again. You can then choose to stage a different subset, or leave the change for later.
This pairs well with git restore filename (no --staged) when you want to throw the change away completely: unstage first, then restore the file.
Challenge
EasyThe folder contains todo.txt committed and secrets.txt not yet committed.
Stage both files, then unstage just secrets.txt. Run git status --short to see the result.
Expected output (note the order): the staged-add line for todo.txt first, then the untracked line for secrets.txt.
Cheat sheet
Unstage a file (keep changes in working directory):
git restore --staged secrets.txtThe --staged flag resets only the staging area; file content is untouched. Without --staged, git restore discards the working directory change entirely.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Version Control
2Getting Started
Initialize A RepositoryThe .git FolderConfigure Your IdentityGit StatusRecap - First Repo8Merging
What Is A MergeFast-Forward MergeThree-Way MergeMerge ConflictsResolve A ConflictRecap - Merge Master11Feature Branch Project
Project OverviewInitialize Main3Tracking Changes
The Staging AreaGit AddGit CommitModifying A Tracked FileGit LogRecap - First Commits6Recipe Site Project
Project OverviewInitialize And Ignore9Undoing Changes
Discard Unstaged ChangesUnstage A FileAmend The Last CommitRevert A CommitReset A BranchRecap - Time Machine