'List commits no longer on branch

Using git only, how do I list commits that were on a branch that are no longer on that branch?

Here I have to use comm/diff

comm -23 <(git reflog @{0} --pretty='%h' | sort -u) <(git log @{0} --pretty='%h' | sort -u)

To test, you can create a couple of commits and hard reset the branch back to its original state. Now the reflog will have commits that were on the branch that are no longer on the branch.

git


Solution 1:[1]

You can use a symmetric difference between two references (... operator):

git log --pretty='%h' HEAD@{1}...HEAD

which is an equivalent of:

git log --pretty='%h' HEAD@{1}...<reset_branch>

both will show the commits no longer reachable from your branch but reachable from HEAD@{1}.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1