1

If I have branch A with commit 1, 2, and 3 and branch B with commits 2, 3, 4 and I'd like to get a list of commits 2 and 3 (A intersect B), is there a git command to do that?

valk
  • 9,363
  • 12
  • 59
  • 79
  • 1
    Branch B with commits 2 and 3 must include commit 1 too. Commit 1 must be in B, I cannot see otherwise. If you have other idea please draw a diagram of the DAG. – phd Mar 22 '22 at 00:24
  • 1
    `git merge-base A B` See https://stackoverflow.com/a/30342089/7976758 and https://stackoverflow.com/q/21881718/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+find+commits+common+two+branches – phd Mar 22 '22 at 00:32

1 Answers1

1

A git merge-base A B would give you commit 3 (the most recent one part of both branches A and B)

1--2--3    (A)
       \
        -4 (B)

But it won't give you 2, considering 1, 2 and 3 are part of both branches anyway.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250