0
0
Gitdevops~5 mins

git restore to discard working changes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the command git restore <file> do?
It discards changes in the working directory for the specified file, restoring it to the last committed state.
Click to reveal answer
beginner
How do you discard all local changes in all files using git restore?
Use git restore . to discard changes in all files in the current directory and its subdirectories.
Click to reveal answer
intermediate
What is the difference between git restore <file> and git checkout -- <file>?
git restore is the newer, clearer command to discard changes, while git checkout -- <file> was used before for the same purpose but also has other uses.
Click to reveal answer
beginner
Can git restore undo changes that have already been committed?
No, git restore only affects uncommitted changes in the working directory. To undo commits, other commands like git revert or git reset are used.
Click to reveal answer
intermediate
What happens if you run git restore <file> on a new untracked file?
Nothing happens because git restore only works on files tracked by Git. Untracked files remain unchanged.
Click to reveal answer
Which command discards changes in a tracked file and restores it to the last commit?
Agit push origin main
Bgit restore &lt;file&gt;
Cgit commit -m 'discard changes'
Dgit add &lt;file&gt;
What does git restore . do?
ARestores all files in the current directory to last commit
BAdds all files to the staging area
CDeletes all files in the directory
DCommits all changes
Can git restore recover deleted commits?
ANo, it deletes commits permanently
BYes, it recovers deleted commits
CYes, but only if used with --hard
DNo, it only affects uncommitted changes
What happens if you run git restore <file> on a new file not tracked by Git?
AThe file is added to Git
BThe file is deleted
CNothing, the file remains unchanged
DThe file is committed
Which command was commonly used before git restore to discard changes in a file?
Agit checkout -- &lt;file&gt;
Bgit reset &lt;file&gt;
Cgit revert &lt;file&gt;
Dgit commit --amend
Explain how to discard changes in a single file using Git and what happens to the file after running the command.
Think about how to undo local edits without affecting commits.
You got /3 concepts.
    Describe the difference between discarding changes with git restore and undoing commits in Git.
    Consider what part of the project each command changes.
    You got /3 concepts.