Git Reverting and Undoing: The Ultimate Quiz Quiz

  1. Reverting a Commit

    Which Git command creates a new commit that undoes the changes made in a specified commit, preserving the history?

    1. git reset --hard
    2. git revert
    3. git undo
    4. git checkout
    5. git restore
  2. Understanding `git reset --hard`

    What does the command `git reset --hard HEAD~1` do?

    1. It moves the HEAD pointer to the previous commit and stages the changes.
    2. It moves the HEAD pointer to the previous commit, discarding the changes in the working directory and staging area.
    3. It reverts the last commit while preserving the changes in the working directory.
    4. It creates a new branch pointing to the previous commit.
    5. It undos the most recent change made to the staging area
  3. Reverting a Merge Commit

    When reverting a merge commit, which option is required to specify which parent the revert should follow?

    1. -m
    2. -p
    3. -f
    4. -r
    5. --mainline
  4. Safety of `git revert`

    Why is `git revert` generally considered safer than `git reset --hard` in shared repositories?

    1. Because it's faster
    2. Because it doesn't alter the commit history, avoiding potential issues for collaborators.
    3. Because it automatically pushes changes to the remote repository.
    4. Because it completely deletes the commit, freeing up space.
    5. Because it is the only way to undo changes.
  5. Undoing a Staged File

    Which command unstages a file but keeps the changes in the working directory?

    1. git reset HEAD file.txt
    2. git restore --staged file.txt
    3. git checkout file.txt
    4. git revert file.txt
    5. git unstage file.txt
  6. Restoring a File

    What is the main purpose of `git restore file.txt`?

    1. Discard changes in the working directory and revert to the last committed version of the file.
    2. Stage the file for the next commit.
    3. Rename the file in the repository.
    4. Delete the file from the repository.
    5. Copy the file into a different directory
  7. Recovering a Lost Commit

    If you accidentally deleted a branch with commits that weren't merged, how can you potentially recover those commits?

    1. Use `git fsck --full --no-reflogs --unreachable --lost-found` to find dangling commits.
    2. Use `git revert --continue` to continue reverting commits that were lost.
    3. The commits are permanently lost; there is no way to recover them.
    4. Use `git merge --abort` to undo the deletion of the branch.
    5. Use `git clean -df` to remove unnecessary files.
  8. Reverting Multiple Commits

    How can you revert a range of commits, for example, the last three commits?

    1. git revert HEAD~3..HEAD
    2. git revert HEAD~2..HEAD
    3. git reset HEAD~3
    4. git checkout HEAD~3..HEAD
    5. git undo HEAD~3..HEAD
  9. Conflict Resolution After Revert

    What should you do if a `git revert` operation results in a merge conflict?

    1. Abort the revert operation immediately.
    2. Resolve the conflicts, stage the changes, and then run `git revert --continue`.
    3. Use `git reset --hard` to discard the conflicting changes.
    4. Ignore the conflicts and push the changes to the remote repository.
    5. Automatically merge the changes by running `git revert -a`.
  10. Undoing a Commit Before Pushing

    You made a commit locally that you want to completely remove *before* pushing to a remote repository. Which command is most appropriate?

    1. git revert HEAD
    2. git push --force
    3. git reset --hard HEAD~1
    4. git clean -df
    5. git checkout HEAD~1