Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git cherry-pick: output resulting new commit sha

I am using git cherry-pick as part of a bash script. For reporting purposes, I would like to output the resulting commit SHA of this cherry-picking to the console. However, there seems to be no option in the cherry-pick command that would return the commit SHA.

Is there a way to get the commit SHA of the commit that was created using a cherry-pick?

like image 780
martin_wun Avatar asked Mar 02 '26 01:03

martin_wun


1 Answers

Since cherry-pick applies the commit on HEAD, you can use the rev-parse command to get the hash of the commit referenced by HEAD after cherry-picking:

git cherry-pick <commit-ref> && git rev-parse HEAD
like image 123
Enrico Campidoglio Avatar answered Mar 03 '26 15:03

Enrico Campidoglio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!