Interview Prep/Git & GitHub/Undoing Mistakes

You merged locally and then realised it was wrong. It has not been pushed.

IntermediateScenarioUndoing Mistakes
Answer

Situation read → A local merge commit can simply be dropped.

What I'd do →

  1. git reset --hard ORIG_HEAD returns to the pre-merge tip if you act right after.
  2. Otherwise: git reset --hard HEAD^1, which moves back to the first parent.
  3. Check with git log --oneline --graph -5.

Why → The merge is only a commit on your local branch, and nobody else has it.

Interview tip → If already pushed, use git revert -m 1 instead.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes