Getting the hash of the last commit when merging #25989
-
I’m using the SHA hash of the last commit as a common value for a few workflows. So when a pull request is made, my PR workflow evaluates When merging the pull request, I have another workflow that triggers on [push]. I’d like to be able to access this same hash. The problem here is that the last commit is now the merge, so really I’m after the second-last commit. My usual tricks with Is there a way to grab this second-last commit hash on merge? Or, equivalently, a way to grab the last commit hash before the merge? Does this hash have a special name that I’m missing? I’d be grateful for any help here. I feel like I’m running up against the boundary of my git knowledge, and my practically non-existent Javascript knowledge. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @mdneuzerling, Glad to see you in Github Community Forum! Since the hash exists in the github.event.commits array, you can use below sample code to get the second-last id, not ideal but it works.
Please refer to my workflow for your reference. weide-zhou/ticket13Contribute to weide-zhou/ticket13 development by creating an account on GitHub. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much, @weide-zhou! That use of For anyone else who comes across this thread in the future:
|
Beta Was this translation helpful? Give feedback.
-
My bad, the |
Beta Was this translation helpful? Give feedback.
Hi @mdneuzerling,
Glad to see you in Github Community Forum!
Since the hash exists in the github.event.commits array, you can use below sample code to get the second-last id, not ideal but it works.
Please refer to my workflow for your reference.
GitHubweide-zhou/ticket13
Contribute to weide-zhou/ticket13 development by creating an account on GitHub.
Thanks.