CS FundamentalsVery hardGATE CS · TCS NQT Prime · Product Company SDE

A developer checks out a specific commit directly by its hash (not a branch name), ending up in 'detached HEAD' state, and then makes two new commits there. What is the risk if they later switch to a branch without creating a new branch at the detached commit first?

  1. A. Those two commits become unreachable from any branch and are at risk of eventual garbage collection, though reflog can usually still recover them for a while
  2. B. The commits are immediately and permanently deleted with no recovery possible
  3. C. The commits are automatically merged into the branch being switched to
  4. D. Git refuses to let you switch branches in this situation

Correct answer: A. Those two commits become unreachable from any branch and are at risk of eventual garbage collection, though reflog can usually still recover them for a while

Commits made in detached HEAD belong to no branch; once HEAD moves elsewhere, they have no ref keeping them reachable and risk being garbage collected, though reflog offers a recovery window.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic