3

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?

1615903
  • 32,635
  • 12
  • 70
  • 99
martin_wun
  • 1,599
  • 1
  • 15
  • 33

2 Answers2

1

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
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
0
git cherry-pick xxx && git log -1 --pretty=%H

If git cherry-pick succeeds, print the new commit sha1.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53