David Brower
David Brower

Reputation: 3048

Get Changeset Id(s) from Merge

In TFVC you can merge changesets from Branch A into Branch B. Is it possible to view which changesets - specifically which ids - from Branch A were merged into Branch B?

Upvotes: 1

Views: 623

Answers (3)

Caio Pavanelli
Caio Pavanelli

Reputation: 1

Just adding another solution for anyone that don't want to use commands, but it will be a bit more time consuming if you want to know more than one merge

On TFS history of the merged branch, you can right click a changeset and choose Track Changeset option and then select the origin branch + merged branch in the next screen

https://learn.microsoft.com/en-us/azure/devops/repos/tfvc/view-where-when-changesets-have-been-merged?view=azure-devops

Upvotes: 0

David Brower
David Brower

Reputation: 3048

Using the tf.exe command line tool, the merges command can provide the merge history between two branches.

So, in my example, from the source control root folder on my local machine I can run the following command in the shell of my choice tf vc merges a b /recursive to get a list of which changesets from a were included in merges to b:

Changeset Merged in Changeset Author                           Date
--------- ------------------- -------------------------------- ----------
   20096                20292 Joey Bloggs                      30/04/2018
   20102                20292 Joey Bloggs                      30/04/2018
   20103                20292 Joey Bloggs                      30/04/2018

Where the first column contains the changeset from branch a and the second column the changeset that merged it into branch b.

In order to get this working I had to add the folder location of tf.exe to my PATH variable.

Upvotes: 0

Amit Baranes
Amit Baranes

Reputation: 8152

You can use the following script :

$tfsUrl = "http://{Server}:{Port}/{Organization}/{Collection}"
$destinationBranchPath = "$/..."
$sourceBranchPath = "$/..."

# Change top with count of changesets you want to check
$body = 'repositoryId=&searchCriteria={"itemPath":"'+ $destinationBranchPath+'","itemVersion":"T","top":50}'
#Get top X changesets under destinationBranchPath
$changeSets  = (Invoke-RestMethod -Method post   "$tfsUrl/{Project}/_api/_versioncontrol/history?__v=5" -Body $body -UseDefaultCredentials).results 

#Run over all changesets and check if sourceBranchPath is part of merage soruce path 
foreach($changeSet in $changeSets)
{
   $IsMerged = (Invoke-RestMethod -Method Get  "$tfsUrl/_apis/tfvc/changesets/$($changeSet.changeList.changesetId)/changes" -UseDefaultCredentials).value.mergeSources.serverItem -like "*$sourceBranchPath*"
   if($IsMerged)
   {
        #Print results 
        Write-Output $changeSet.changeList
   }
}

Upvotes: 1

Related Questions