CS FundamentalsVery hardProduct company interview · GATE level

main has commits A-B-C-D-E (E is main's tip). feature was created at C and got commits F and G; then main was merged into feature, creating merge commit H (parents G and E), and one more commit I was made on feature. How many commits does git log main..feature list, and how many does git log feature..main list?

  1. A. 4 and 2
  2. B. 4 and 0
  3. C. 3 and 2
  4. D. 2 and 0

Correct answer: B. 4 and 0

git log X..Y lists commits reachable from Y but not from X. From feature (I) you reach I, H, G, F and, through H's second parent, E, D, C, B, A. From main (E) you reach E, D, C, B, A. So main..feature is I, H, G, F: 4 commits, including the merge commit. feature..main is empty, because after the merge every commit on main is also reachable from feature - D and E are not 'only on main' any more.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic