I want to compare the differences between two branches at two specific commit points, and the all the commits that contributed to these differences. For example, let's consider the tokio repository. I want to compare the differences between version 1.9.0 (commit b280c6d at 1.9.x branch) and version 1.8.4 (commit 2273eb1 at 1.8.x branch). When I do git diff 2273eb1 b280c6d, I can see the changes in code between the two commit points. My goal is to list all the commits that contributed to these changes (diff).
To achieve this goal, I did git log --pretty=%H 2273eb1...b280c6d which returns me 53 commits, 34 commits on the 1.9.x branch and 19 commits on the 1.8.x branch. However, the problem is that the 1.8.x branch was merged into 1.9.x twice since their oldest common ancestor. These two merge commits are present within the 34 commits coming from 1.9.x branch, and therefore represents code changes present both in version 1.9.0 and 1.8.4 (therefore, not part of the diff between them). My goal is to detect these two commits and not count them, or in other words, get only the 51 commits that contributed to the code changes between the two version. How can I achieve this?
Note that, I tried another approach git log --pretty=%H --ancestry-path 2273eb1...b280c6d, which returns 28 commits, 9 from the 1.9.x branch and 19 from 1.8.x branch. However, this command cuts the commits from 1.9.x branch at the two versions' latest common ancestor, and therefore, missed some prior commits that went into 1.9.x branch (and results in the difference between 1.9.0 and 1.8.4.)