I am wondering if it's possible to fetch only a single file from a Git repository in order to commit a new change to it. We want to change the file on a Azure DevOps Hosted Agent however downloading the entire repo would take a significantly long time, as it is large.
I read of these options:
Filter command attempt
git clone --depth 1 --filter=sparse:path=ReadMe.md
warning: filtering not recognized by server, ignoring
Sparse checkout
git config core.sparsecheckout true
echo File.txt >> .git/info/sparse-checkout git pull origin master
However it still retrieved everything.
The server repository is running GIT v2.18.
Thank you.
The best way to download one file from Git repo is with Azure DevOps Rest API - Items - Get.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=5.0-preview.1
If you add the parameter download
(for example: ?path={path}&download=true
) the file will be downloaded on the agent.
So add a task with a simple PowerShell script (with Invoke-RestMethod
) and get the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With