Challenge - 5 Problems
Git Restore Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output after discarding changes with git restore?
You have modified a file named
app.js in your working directory. You run the command git restore app.js. What happens to the file app.js?Attempts:
2 left
💡 Hint
Think about what 'restore' means in the context of undoing changes.
✗ Incorrect
The git restore command resets the file in the working directory to match the last commit, discarding any changes made since then.
💻 Command Output
intermediate2:00remaining
What error occurs if you run git restore on a file not tracked by git?
You create a new file
notes.txt but never added it to git. You run git restore notes.txt. What is the result?Attempts:
2 left
💡 Hint
Consider what git knows about the file before restoring.
✗ Incorrect
Git cannot restore a file it does not track. It will show an error that the pathspec did not match any files.
🔀 Workflow
advanced2:00remaining
Which command sequence discards all local changes in the working directory?
You want to discard all local changes in your working directory for all tracked files. Which command sequence achieves this?
Attempts:
2 left
💡 Hint
Focus on discarding changes only, not deleting untracked files.
✗ Incorrect
git restore . discards all changes in tracked files in the current directory and below. git reset --hard also resets the index and HEAD, which is more than just discarding working changes.
❓ Troubleshoot
advanced2:00remaining
Why does git restore not discard changes in a file?
You run
git restore config.yaml but your changes in config.yaml remain. What is the most likely reason?Attempts:
2 left
💡 Hint
Think about whether git knows about the file.
✗ Incorrect
If the file is untracked, git restore cannot discard changes because git does not manage it yet.
✅ Best Practice
expert2:00remaining
What is the safest way to discard changes in a file without affecting the staging area?
You have changes in
index.html both staged and unstaged. You want to discard only the unstaged changes, keeping the staged ones intact. Which command should you use?Attempts:
2 left
💡 Hint
Consider the difference between restoring staged and unstaged changes.
✗ Incorrect
git restore index.html discards only unstaged changes in the working directory, leaving staged changes untouched. Using --staged affects the staging area instead.