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.
CodePudding user response:
git reflog --pretty=%H $thatbranch | git rev-list --stdin --not $thatbranch
and you can sub in git log
for git rev-list
to get more than just a list.
CodePudding user response:
You can use a symmetric difference between two references:
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}
.