CS FundamentalsVery hardProduct-company placement · Git

main has A-B-C. feature branched from B and has D-E. On main you run git merge feature, creating merge commit M (first parent C, second parent E). With HEAD at M, what do HEAD^2 and HEAD~2 name?

  1. A. HEAD^2 = B and HEAD~2 = E
  2. B. HEAD^2 = E and HEAD~2 = B
  3. C. HEAD^2 = C and HEAD~2 = B
  4. D. HEAD^2 = E and HEAD~2 = D

Correct answer: B. HEAD^2 = E and HEAD~2 = B

^n picks the nth parent of a commit, so M^2 is E. ~n follows first parents n times: M~1 = C and M~2 = B. Following the second parent twice would give D, which is the trap.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic