Explore essential concepts for undoing changes in Git, focusing on the differences and use-cases of reset, revert, and checkout commands. This quiz challenges you to identify correct scenarios and effects when managing change history within version control workflows.
When using 'git reset --hard HEAD~1', what is the primary effect on your repository's history and working directory?
Explanation: The 'git reset --hard HEAD~1' command erases the last commit and forces your working directory and index to match the new branch tip, discarding any unstaged and staged changes. The second option only describes a soft reset, which does not affect the working directory. The third option refers to 'revert', which actually creates a new commit. The fourth option relates to adding or staging changes, not resetting.
Which statement best describes what happens when you run 'git revert b6f1d91'?
Explanation: 'git revert' is used to create a new commit that reverses the effect of a specific commit, preserving project history. It does not delete any commits, making option two incorrect. Option three is closer to what 'checkout' does, not revert. Option four describes staging, which is not part of revert's functionality.
If you run 'git checkout -- README.md', what outcome should you expect in your working directory for that file?
Explanation: The 'git checkout -- README.md' command overwrites the file in the working directory with the version from the last commit, discarding any local modifications. The file is not deleted, so option two is inaccurate. Option three describes a renaming action not performed by checkout. Option four refers to staging, which is typically done by 'git add'.
In a collaborative environment, which situation is most appropriate for using 'git revert' instead of 'git reset'?
Explanation: 'git revert' is best in collaborative workflows to undo changes without affecting project history, making it safe for shared branches. Using 'reset' on shared branches can cause problems for others by rewriting history, which option two incorrectly suggests. Removing untracked files is achieved with cleaning commands, not revert or reset, making option three incorrect. Option four actually refers to 'checkout', not revert.
What does running 'git reset --soft HEAD~2' do to your current branch and staged changes?
Explanation: 'git reset --soft HEAD~2' only moves the branch pointer, keeping all changes from the undone commits staged and ready for recommit. It does not delete files, which makes the second option untrue. The third option is what 'git revert' does, not reset. The fourth option suggests branch manipulation, which is unrelated to this command.