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. |



