3

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.

cybersnow1989
  • 229
  • 3
  • 17

2 Answers2

1

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.

TTT
  • 22,611
  • 8
  • 63
  • 69
0

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

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39