CodeBlanks Logo Icon CodeBlanks

Unstage

Learn to unstage a file that was added.

Unstage a staged file

After adding a file with git add, you may want to undo that operation. The git restore --staged file.txt command removes the file from the staging area while preserving its working tree changes. You can then edit the file again or stage it later.

git add report.txt
git restore --staged report.txt
git status

This operation does not delete the file content; it only changes its staging state.

Unstage and reset

Another way to unstage changes is the git reset HEAD file.txt command. This usage reverses the file's staging entry while preserving its working tree edits. The modern and explicit alternative is git restore --staged.

git add notes.txt
git reset HEAD notes.txt
git status

The goal here is not to delete the latest commit, but only to change the file's staging state.

Practice Undo staging

The content.html file was previously added to the staging area with git add. Unstage the file, preserve its working tree changes, and then check the status.

Starter code

terminal
# Dosyayı sahneden çıkar

# Durumu kontrol et

Sample solution

terminal
git restore --staged icerik.html
git status

Expected output

On branch main
Changes not staged for commit:
  modified:   icerik.html

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How do you preserve changes while unstaging a file?

  • git restore --staged file.txt Correct answer
  • git restore file.txt
  • git rm file.txt
  • git checkout -- file.txt

Explanation: The <code>--staged</code> option unstages the file while preserving its working tree changes.

2 Unstage a file

Question
git restore ____ 
Answer
git restore --staged 

Explanation: The <code>--staged</code> option reverses the file's staging state and preserves its working tree content.

3 Unstage concepts

Term Meaning
Staging area Area before a commit
--staged Unstaging option
git reset HEAD Older unstaging method
Working tree Area where edits are kept

All lessons in Beginner