How to ignore cherry-picked commits when listing commits difference with a fully merged branch

Viewed 272

In a branching model where one branch A is always merged into another B, how can I list all commits in B but not in A while ignoring all cherry-picked commits and merges?

     a1-------b2' -- A
   /    \       \
 b1--b2--m1--b3--m2--b4 -- B

b2': cherry-picked commit

In this case, it should list commits b3, b4.

Some research in the git manual:
Ignoring merges and cherry-picked commits is already addressed by the --no-merges and --cherry-* options of the git-log command. But the --cherry-* ones use the commits symmetric difference (that is A...B) to match cherry-picks together. In this example, commit b2 is not part of it. git log --cherry A...B returns b2, b3, b4.

You can reproduce the example with:

mkdir reprod; cd reprod; git init
git check-out -b B
git commit -m "b1" --allow-empty
git commit -m "b2" --allow-empty
git check-out -b A B^{/b1}
git commit -m "a1" --allow-empty
git cherry-pick --allow-empty B^{/b2}
git check-out B
git merge A^{/a1} --no-edit
git commit -m "b3" --allow-empty
git merge A^{/b2} --no-edit
git commit -m "b4" --allow-empty
git log A...B --cherry
1 Answers

(Failed hypothesis - kept here for history only)

It seems you'd have to use --left-only / --right-only here.

See in this paragraph.

For example, --cherry-pick --right-only A...B omits those commits from B which are in A or are patch-equivalent to a commit in A. In other words, this lists the + commits from git cherry A B. More precisely, --cherry-pick --right-only --no-merges gives the exact list.

Isn't it your exact case?

Related