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.

Want to know how to develop your skillset to become a Java Rockstar?

Join our newsletter to start rocking!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

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