我希望删除SBX分支,并使用现有的DEV分支创建一个名为SBX的新分支,因此基本上用DEV覆盖SBX。如果有办法在一次又一次地重写一个分支,我也会对它感兴趣。截图供参考
我想用Powershell/API来做这件事,我看了下面的参考文献表,但是不知道如何使用这些API。
例如,我运行了以下命令来获取分支的列表
https://dev.azure.com/jaredsplayground/JaredsPlayground/_apis/git/repositories/Jared/refs?api-version=6.0
但请回到以下几点:
Azure DevOps Services | Sign In
思考我做错了什么,以及如何用DEV覆盖SBX?
谢谢,
发布于 2022-10-28 07:00:22
没有试图覆盖。但是我们可以在DEV分支的基础上创建新的分支。
请确保您已经创建了一个具有正确范围的PAT。详情请参见使用个人访问令牌。
通常,我们可以基于现有的分支或提交创建分支,因此newObjectId
实际上是特定分支或提交ID的ObjectID
。
我们可以使用以下REST获得现有分支的ObjectID
:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repository_ID}/refs?api-version=5.1
并使用这个REST获得提交:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repository_ID}/commits?api-version=5.1
然后,我们可以使用特定的ObjectID
或CommitID
创建一个新分支。
下面的PowerShell脚本用于您的参考以创建一个新分支:
Param(
[string]$collectionurl = "https://dev.azure.com/{organization}",
[string]$project = "projectname",
[string]$repoid = "62c8ce54-a7bb-4e08-8ed7-40b27831bd8b",
[string]$Newbranch_name = "Test",
[string]$newObjectId= "Existing Branch objectID or the commit ID ",
[string]$user = "",
[string]$token = "PAT-Here"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
function CreateJsonBody
{
$value = @"
[ { "name": "refs/heads/$Newbranch_name",
"oldObjectId": "0000000000000000000000000000000000000000",
"newObjectId": "$newObjectId" } ]
"@
return $value
}
$json = CreateJsonBody
# Create new Branch
$NewBranch = "$collectionurl/$project/_apis/git/repositories/$repoid/refs?api-version=5.1"
Invoke-RestMethod -Uri $NewBranch -Method POST -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
更新:
DevOps在TFVC上没有相同的REST。见TFVC。您可以尝试使用相关的TFVC命令,tf支路作为参考。
您也可以尝试使用Git回购而不是TFVC回购。只需将TFVC回购导入到一个新的Git回购。详情请参见将存储库从TFVC导入到Git。
https://stackoverflow.com/questions/74228638
复制