Menu
Coddy logo textTech

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.txt

The --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 icon

Challenge

Easy

The 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.txt

The --staged flag resets only the staging area; file content is untouched. Without --staged, git restore discards the working directory change entirely.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control