如何使用VSTS Git API获取指定Git分支的全部内容?
How to Download Full Content from a Specific Branch Using the VSTS Git API
Perfect that you’ve already spotted the core solution! Let me break down the exact implementation to make sure you can pull content from any target branch smoothly:
You’re already using the correct Get Items API endpoint to fetch repository content, which defaults to the master branch out of the box. To redirect the request to your desired branch, all you need to do is include the versionDescriptor parameter in your call, with its version field set to the name of your target branch.
Key Details for Reliable Results:
- Always set
versionDescriptor.versionTypetobranchexplicitly. This tells the API that the value you’re passing is a branch name (not a commit SHA or tag), eliminating any potential ambiguity in the request. - You can pass this parameter either as query string parameters in a GET request, or as part of the request body if you’re using a POST call.
Example GET Request URL:
https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path=/&versionDescriptor.version=feature/my-custom-branch&versionDescriptor.versionType=branch&api-version=7.1-preview.1
Example POST Request Body:
{ "path": "/", "versionDescriptor": { "version": "feature/my-custom-branch", "versionType": "branch" }, "api-version": "7.1-preview.1" }
With this setup, the API will return the complete content of your specified branch instead of defaulting to master.
内容的提问来源于stack exchange,提问作者Rohi_Dev_1.0
相关产品推荐
相关产品推荐

