Software Development

Selecting Git commits by message

 

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.

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Selecting Git commits by message

Opinions expressed by Java Code Geeks contributors are their own.

Sebastian Daschner

Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button