CS FundamentalsVery hardProduct-company placement · Git interview

On main (…-C-D) you run git merge feature, where feature has E-F-G, creating merge commit M. Its first parent is D and its second is G. With HEAD at M, which pair is correct?

  1. A. HEAD^2 is G and HEAD~2 is C
  2. B. HEAD^2 is C and HEAD~2 is G
  3. C. HEAD^2 and HEAD~2 are both C
  4. D. HEAD^2 is F and HEAD~2 is C

Correct answer: A. HEAD^2 is G and HEAD~2 is C

^n picks the n-th parent of a commit, so HEAD^2 = G (the merged-in tip). ~n follows first parents n times: M → D → C, so HEAD~2 = C. They coincide only for non-merge commits' ^1 and ~1.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic