CS FundamentalsHardWipro · Accenture pattern

A bad commit has already been pushed to a shared main branch that teammates have pulled. What is the safest way to undo it?

  1. A. git reset --hard <commit>~1 followed by git push --force
  2. B. git commit --amend
  3. C. Delete the branch and push it again
  4. D. git revert <commit>, which adds a new commit that undoes the change

Correct answer: D. git revert <commit>, which adds a new commit that undoes the change

git revert keeps history intact and is safe for shared branches. Resetting and force-pushing rewrites history that others already have, breaking their clones; --amend only edits the latest commit and also rewrites history.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic