0
0
Gitdevops~20 mins

git restore to discard working changes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Restore Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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?
AThe changes in <code>app.js</code> are discarded and the file is restored to the last committed state.
BThe changes in <code>app.js</code> are staged for commit but not discarded.
CThe file <code>app.js</code> is deleted from the working directory.
DThe changes in <code>app.js</code> are committed automatically.
Attempts:
2 left
💡 Hint
Think about what 'restore' means in the context of undoing changes.
💻 Command Output
intermediate
2: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?
AThe file <code>notes.txt</code> is deleted from the working directory.
BThe file <code>notes.txt</code> is restored to an empty file.
CThe file <code>notes.txt</code> is added to the staging area.
DError: pathspec 'notes.txt' did not match any files
Attempts:
2 left
💡 Hint
Consider what git knows about the file before restoring.
🔀 Workflow
advanced
2: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?
Agit clean -fd
Bgit reset --hard
Cgit restore .
Dgit checkout master
Attempts:
2 left
💡 Hint
Focus on discarding changes only, not deleting untracked files.
Troubleshoot
advanced
2: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?
AYou need to run <code>git commit</code> first.
BThe file <code>config.yaml</code> is untracked by git.
CThe file is locked by another process.
DYou forgot to add the <code>--staged</code> option.
Attempts:
2 left
💡 Hint
Think about whether git knows about the file.
Best Practice
expert
2: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?
Agit restore index.html
Bgit restore --staged index.html
Cgit reset index.html
Dgit checkout -- index.html
Attempts:
2 left
💡 Hint
Consider the difference between restoring staged and unstaged changes.