Azure Pipelines find commit hash of incoming merge

Viewed 678

I'm relatively new to git and am having the below problem

I have a pipeline, and I'm trying to find the commit hash of the incoming pull request / merge, store it, and use it elsewhere in a simple git log command.

So is there a git command (or powershell script) that can find the incoming merge commit hash of a PR?

Sorry in advance if the answer is obvious my google fu did not help with this one.

2 Answers

This command should work. If you just pass in the PR number you will receive a JSON response of type GitPullRequest:

_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}

{pullRequestId} might be 1234, for example.

Included in the JSON response are different commit IDs, including lastMergeCommit, lastMergeSourceCommit, and lastMergeTargetCommit. Take a look at those IDs to confirm which one you want. You can also access an array of commits contained in the PR.

If you want to see every commits merged in the last merge you can try that :

git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P)).. --boundary

Check this case for more details: Show commits involved in a prior git merge

Related