CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE

A developer runs `git reset --hard HEAD~3` on a local branch, discarding the last 3 commits and their changes from the working directory. Are those commits permanently lost?

  1. A. They are only lost if the repository has no remote configured
  2. B. Not immediately; they usually remain recoverable via git reflog until Git's garbage collector eventually prunes unreachable objects
  3. C. Yes, they are deleted from disk the instant the command runs
  4. D. No, they automatically reappear the next time you commit

Correct answer: B. Not immediately; they usually remain recoverable via git reflog until Git's garbage collector eventually prunes unreachable objects

A hard reset only moves the branch pointer and updates the working tree; the old commits still exist as unreachable objects and can usually be found via reflog until garbage collection eventually removes them.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic