sebastiandaschner blog


Selecting Git commits by message

#git #commandline sunday, january 06, 2019

In order to checkout, cherry-pick, or reset Git commits, you don’t have to provide their SHA commit hash. All commits can be referred to by their message, by using the pattern :/<part-of-message>, which comes in very handy when using Git from the command line.

Given the following commit history:

caeb1d8 (HEAD) commit 4
2f6d4da commit 3
8207cf2 commit 2
551ef47 commit 1
22f759b initial commit

We can checkout commit 551ef47 by git checkout ':/commit 1'.

The pattern will search the history backwards, for the first commit where the provided string is part of the commit’s message. Therefore, It’s also possible to do git checkout :/initial in order to checkout 22f759b.

This post was reposted from my newsletter issue 024.

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: