0
0
Gitdevops~20 mins

git restore --staged to unstage - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Unstage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of unstaging a file with git restore --staged?
You have staged a file named example.txt. You run git restore --staged example.txt. What happens to the file's state?
AThe file is committed automatically.
BThe file is deleted from the working directory and staging area.
CThe file is staged again with no changes.
DThe file is removed from the staging area but changes remain in the working directory.
Attempts:
2 left
💡 Hint
Think about what 'unstaging' means in Git.
🧠 Conceptual
intermediate
1:30remaining
Which command correctly unstages a file in Git?
You accidentally staged a file named config.yaml. Which command will unstage it without losing your changes?
Agit restore --staged config.yaml
Bgit rm --cached config.yaml
Cgit commit --amend config.yaml
Dgit reset --hard config.yaml
Attempts:
2 left
💡 Hint
Unstaging means removing from the index but keeping the file.
Troubleshoot
advanced
2:00remaining
Why does git restore --staged not remove changes from the working directory?
You ran git restore --staged README.md but your changes in the file are still visible. Why?
ABecause <code>git restore --staged</code> only removes the file from the staging area, not the working directory.
BBecause the file is locked by another process.
CBecause the command requires the <code>--worktree</code> option to remove changes.
DBecause the file was never staged to begin with.
Attempts:
2 left
💡 Hint
Think about the difference between staging area and working directory.
🔀 Workflow
advanced
2:00remaining
What is the correct sequence to unstage a file and then discard its changes?
You staged and modified app.js. You want to unstage it and also remove all changes, restoring it to the last commit. Which sequence is correct?
Agit reset HEAD app.js; git rm app.js
Bgit restore app.js; git restore --staged app.js
Cgit restore --staged app.js; git restore app.js
Dgit commit --amend; git restore app.js
Attempts:
2 left
💡 Hint
First remove from staging, then discard changes.
Best Practice
expert
2:30remaining
Which command safely unstages all files without discarding any changes?
You have multiple files staged but want to unstage all of them at once without losing any work. Which command should you use?
Agit reset --hard
Bgit restore --staged .
Cgit clean -fd
Dgit rm --cached -r .
Attempts:
2 left
💡 Hint
Unstage all files but keep changes intact.