Git: Show commits that come after

Zag-zigging through the git log

git log with a commit SHA shows that commit and those before it:

$ git log --oneline c927ee2
c927ee2 Heat-treat the non-stick coating
5c8f5fc Apply non-stick coating
2f14e86 Stamp body of pan
...

(--oneline activates the short one-line format.)

To show the commits that come after the given SHA, use:

$ git log --oneline --reverse <target>..<later>

Replace <target> with the queried commit SHA (or other reference, such as a tag). Replace <later> with any definitely-later commit reference. If you know <target> was merged to your main branch, <later> can be your main branch name.

For example:

$ git log --oneline --reverse c927ee2..main
e8345ff Screw handle to body
1722f2e Run quality checks
2dfc9bb (HEAD -> main) Put pan in box

The double-dot syntax selects all commits between the two commit references. --reverse swaps the log sort order the log from the usual one, putting the earliest commits first.

This little trick with --reverse is necessary because of Git’s design. Commits refer to their previous (“parent”) commits, but not the next ones (“children”). So, to see later commits, we have to look at the backwards log and reverse it. Thankfully, this process doesn’t take long, even in large repositories.

Fin

May you always know where you are,

—Adam


Read my book Boost Your Git DX for many more Git lessons.


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: