Skip to content

Find a git commit from the command line

 Published on 22nd March 2023

When I’m working in a codebase I sometimes need to find a previous commit. Until recently I would either do a git log or view the history in GitHub, but sometimes the commit might be buried under a sea of commits and be difficult to find.

It is possible to actually search for a commit on the command line, meaning you don’t need to know the commit hash or the exact message, or even when the commit was made.

git log --all --grep="SEARCH_TERM"

This is something I only learned about a couple of months ago and I have found it really useful when I want to quickly find a commit without trawling through a list of mostly unrelated messages.