QuestenaPractice that shows what to review next
Question 12

A faulty commit has already been pushed to a shared branch your teammates work on. Which command undoes its changes without rewriting the branch's existing history?

  1. git reset --hard HEAD~1 followed by a force push
  2. git commit --amend
  3. git checkout <faulty-commit>
  4. git revert <faulty-commit>Correct answer

Explanation

`git revert` creates a new commit that applies the inverse of the faulty commit's changes, so history only grows — safe on a shared branch. `git reset --hard` plus a force push and `git commit --amend` both rewrite published history, forcing every teammate to repair their local branches. `git checkout <commit>` merely moves you to that commit (detaching HEAD) and undoes nothing on the branch.

Continue with this test

Start practice
Question 12: A faulty commit has already been pushed to a shared branch… · Git Fundamentals · Questena