cybersnow1989
cybersnow1989

Reputation: 331

Azure Pipelines find commit hash of incoming merge

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.

Upvotes: 3

Views: 1897

Answers (2)

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31083

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

Upvotes: 0

TTT
TTT

Reputation: 29054

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.

Upvotes: 1

Related Questions