Undo a bad commit that is already on shared main
QuizMediumAsked in: Accenture, Capgemini, TCS, Wipro
A commit that broke the test suite is already pushed to the shared main branch, and teammates have pulled it. What is the safe way to undo it?
- git revert COMMIT_ID, then push: it adds a new commit that undoes the change without rewriting history
- git reset --hard HEAD~1, then git push --force
- git commit --amend
- git stash
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.