AI Hints
Home›Git & GitHub Tutorial›Interview Questions 2
Git & GitHub · Lesson 135 of 144

Interview Questions: Undoing

Reset, revert and more.

⏱ 2 min read▶ Video at 2:27:17🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Undoing things is where people get nervous, and interviewers know it. Calm, correct answers here really stand out.

Interview Questions: Undoing
From the video: Interview Questions: Undoing
  • Undoing makes people nervous
  • Interviewers know it
  • Calm answers stand out

Reset versus revert?

Question seven. What's the difference between git reset and git revert? Reset moves your branch back to an earlier commit, removing the later ones from the branch. It rewrites history, so it's for local commits only. Revert creates a new commit that undoes an earlier one. History is kept, so it's safe for shared branches.

git reset

  • Moves the branch back
  • Rewrites history
  • Local commits only

git revert

  • Adds an undo commit
  • Keeps history
  • Safe when shared

Soft, mixed and hard?

Question eight. What do soft, mixed and hard mean in git reset? They all move the branch. Soft keeps your changes staged. Mixed, the default, keeps them, but unstaged. Hard throws them away. Mention that hard can lose uncommitted work.

ModeYour changes
--softkept, staged
--mixed (default)kept, unstaged
--harddiscarded

How do you recover a lost commit?

Question nine. How do you recover a commit after a bad reset? Use git reflog. It lists every position head has been at. Find the lost commit's hash, then reset back to it, or create a branch at it. Mention that the reflog is local, and kept for around ninety days.

git reflogwhere HEAD has been
Findthe lost hash
Recoverreset or branch
Limitlocal, ~90 days

Summary

Reset versus revert, the three reset modes, and the reflog. Next, a final round of questions about teams and good practice.

Key takeaways
  • reset: local, rewrites
  • revert: shared, safe
  • reflog: the safety net
Next up: Interview Questions: Teamwork — workflows and good habits