List only the commits of a given branch

Rationale TL;DR

Imagine that you have a git branch and you want to list only the commits of that branch, avoiding commits from other branches, merges, etc …

Doing it

In fact, it’s pretty easy to achieve. What we want is to list the commit list on a

git rev-list --all --not $(git rev-list --all ^BRANCH_NAME) | tail -r

This will reverse the list of commits on the branch BRANCH_NAME. That is really usefull if we want to cherry-pick commits from another branch, for example:

git rev-list --all --not $(git rev-list --all ^BRANCH_NAME) | tail -r | xargs -L 1 -I COMMIT git cherry-pick COMMIT