CS FundamentalsHardWipro · Accenture pattern

You checked out an old commit by its hash, made two commits, then ran git checkout main. What happened to those two commits?

  1. A. They were deleted immediately and cannot be recovered
  2. B. They were automatically added to main
  3. C. They still exist but are not on any branch; they can be recovered with git reflog and a new branch, until garbage collection removes them
  4. D. They were moved to a branch called HEAD

Correct answer: C. They still exist but are not on any branch; they can be recovered with git reflog and a new branch, until garbage collection removes them

In detached-HEAD state new commits belong to no branch. After switching away they become unreachable but remain in the object store and reflog (by default for weeks); git branch rescue <hash> saves them.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic