CS FundamentalsVery hardProduct-company placement · Git interview

A merge commit M on main brought in a feature that turns out to be broken. Running git revert M fails. Why, and what is the fix?

  1. A. Merge commits can never be reverted; reset main instead
  2. B. A merge has two parents, so git must be told which side is the mainline: git revert -m 1 M
  3. C. git revert works only on the latest commit; use git revert HEAD~1
  4. D. The working tree must first be cleaned with git clean -fd

Correct answer: B. A merge has two parents, so git must be told which side is the mainline: git revert -m 1 M

git refuses ('is a merge but no -m option was given') because it cannot know which parent to diff against. -m 1 keeps main's side and undoes the feature's changes. Note that re-merging the feature later needs care, because its commits are already in history.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic