SOLVED

Trying to down just specific file in Azure repo to Windows and Linux.

%3CLINGO-SUB%20id%3D%22lingo-sub-1503176%22%20slang%3D%22en-US%22%3ETrying%20to%20down%20just%20specific%20file%20in%20Azure%20repo%20to%20Windows%20and%20Linux.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1503176%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20new%20to%20Azure%20and%20created%20a%20text%20file%20to%20test%20with%20in%20my%20Azure%20repo.%20I%20have%20the%20command%20%22git%22%20on%20Windows%20to%20download%20from%20the%20Windows%20server%20and%20%22wget%22%20or%20%22curl%22%20on%20Linux.%20Could%20somebody%20give%20me%20the%20syntax%20to%20download%20my%20test%20flat%20file%3F%20I%20am%20having%20no%20luck.%26nbsp%3B%20On%20Windows%2C%20I%20can%20clone%20my%20my%20repo%20via%20the%20following%20command%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26gt%3Bgit%20clone%20%3CA%20href%3D%22https%3A%2F%2FGregSmith0896%40dev.azure.com%2FGregSmith0896%2FWebSphere%2F_git%2FWebSphere%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FGregSmith0896%40dev.azure.com%2FGregSmith0896%2FWebSphere%2F_git%2FWebSphere%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20Linux%2C%20again%20I%20can%20download%20the%20repo%20with%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26gt%3Bwget%20clone%20%3CA%20href%3D%22https%3A%2F%2FGregSmith0896%40dev.azure.com%2FGregSmith0896%2FWebSphere%2F_git%2FWebSphere%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FGregSmith0896%40dev.azure.com%2FGregSmith0896%2FWebSphere%2F_git%2FWebSphere%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20just%20download%20a%20specific%20file%20in%20the%20repo%20which%20exists%20in%20the%20branch%20%22scripts%22%20and%20the%20file%20name%20is%20%22test.txt%22%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20let%20me%20know.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1504370%22%20slang%3D%22en-US%22%3ERe%3A%20Trying%20to%20down%20just%20specific%20file%20in%20Azure%20repo%20to%20Windows%20and%20Linux.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1504370%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Repos%20are%20based%20off%20%3CA%20href%3D%22https%3A%2F%2Fgit-scm.com%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Estandard%20git%3C%2FA%3E%2C%20and%20there%20are%20many%20suggestions%20out%20there%20for%20downloading%20individual%20files%2C%20for%20example%2C%20you%20could%20create%20an%20archive%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markdown%22%3E%3CCODE%3Egit%20archive%20--format%3Dzip%20HEAD%20test.txt%20-o%20test.zip%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eor%20you%20could%20use%20%3CA%20href%3D%22https%3A%2F%2Fgit-scm.com%2Fdocs%2Fgit-sparse-checkout%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Esparse%20checkout%2C%3C%2FA%3E%20which%20clones%20the%20repo%2C%20but%20%22hides%22%20certain%20files%20you%20are%20not%20interested%20in%2C%20this%20is%20an%20experimental%20feature%2C%20so%20be%20careful.%3C%2FP%3E%3CP%3EAlternatively%2C%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fazure%2Fdevops%2Fgit%2Fblobs%2Fget%2520blob%3Fview%3Dazure-devops-rest-5.1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EgetBlob%3C%2FA%3E%20Api%20may%20be%20of%20use%2C%20which%20appears%20to%20allow%20you%20to%20download%20specified%20files%20directly%20from%20the%20repo%3A%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3EGET%20https%3A%2F%2Fdev.azure.com%2F%7Borganization%7D%2F%7Bproject%7D%2F_apis%2Fgit%2Frepositories%2F%7BrepositoryId%7D%2Fblobs%2F%7Bsha1%7D%3Fdownload%3D%7Bdownload%7D%26amp%3BfileName%3D%7BfileName%7D%26amp%3B%24format%3D%7B%24format%7D%26amp%3BresolveLfs%3D%7BresolveLfs%7D%26amp%3Bapi-version%3D5.1%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EDepending%20on%20your%20use%20case%2C%20you%20might%20also%20consider%20adding%20a%20task%20to%20your%20Azure%20DevOps%20Release%20pipeline%20to%20copy%20the%20required%20files%20to%20a%20specified%20locaton%20(e.g.%20AzureBlob%20File%20Copy).%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-yaml%22%3E%3CCODE%3Esteps%3A%0A-%20task%3A%20AzureFileCopy%404%0A%20%20displayName%3A%20'AzureBlob%20File%20Copy'%0A%20%20inputs%3A%0A%20%20%20%20SourcePath%3A%20'%24(System.DefaultWorkingDirectory)%5CBuild%5Csite%5C%24(Build.BuildId)%5Ctest.txt'%0A%20%20%20%20azureSubscription%3A%20'Visual%20Studio%20Enterprise%20(bc180cfa-8d6b-46bc-97d6-aeaab72b18c4)'%0A%20%20%20%20Destination%3A%20AzureBlob%0A%20%20%20%20storage%3A%20sitestaging%0A%20%20%20%20ContainerName%3A%20'%24web'%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1511912%22%20slang%3D%22en-US%22%3ERe%3A%20Trying%20to%20down%20just%20specific%20file%20in%20Azure%20repo%20to%20Windows%20and%20Linux.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1511912%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F718566%22%20target%3D%22_blank%22%3E%40Scott_Gray%3C%2FA%3E%26nbsp%3BThank%20you%20for%20the%20information.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20getting%20the%20following%20when%20I%20try%20to%20download%20and%20create%20a%20container%20..%20such%20as%20a%20zip%20file%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EC%3A%5CUsers%5Cgrsm001%5Cgit%26gt%3Bgit%20archive%20--format%3Dzip%20HEAD%20test.txt%20-o%20test.zip%3CBR%20%2F%3Efatal%3A%20not%20a%20valid%20object%20name%3A%20HEAD%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoing%20a%20Git%20status%20shows%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EC%3A%5CUsers%5Cgrsm001%5Cgit%26gt%3Bgit%20status%3CBR%20%2F%3EOn%20branch%20scripts%3C%2FP%3E%3CP%3ENo%20commits%20yet%3C%2FP%3E%3CP%3EUntracked%20files%3A%3CBR%20%2F%3E(use%20%22git%20add%20%3CFILE%3E...%22%20to%20include%20in%20what%20will%20be%20committed)%3CBR%20%2F%3Etest.zip%3C%2FFILE%3E%3C%2FP%3E%3CP%3Enothing%20added%20to%20commit%20but%20untracked%20files%20present%20(use%20%22git%20add%22%20to%20track)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20help%20me%20with%20the%20syntax%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20I%20am%20not%20versed%20in%20using%20GET.%20Is%20there%20a%20command%20I%20can%20use%20this%20with%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1514502%22%20slang%3D%22en-US%22%3ERe%3A%20Trying%20to%20down%20just%20specific%20file%20in%20Azure%20repo%20to%20Windows%20and%20Linux.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1514502%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%20size%3D%224%22%3EI%20was%20able%20to%20find%20a%20solution%20per%20this%20thread%3A%20%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F2466735%2Fhow-to-sparsely-checkout-only-one-single-file-from-a-git-repository%2F19501643%2319501643%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F2466735%2Fhow-to-sparsely-checkout-only-one-single-file-from-a-git-repository%2F19501643%2319501643%3C%2FA%3E%3C%2FFONT%3E%20-%20using%20the%20-n%20parameter%20clone%20the%20branch%20without%20downloading%20anything%20then%20using%20the%20%22checkout%22%26nbsp%3B%20command%20with%20%22HEAD%22%2C%20you%20can%20download%20a%20single%20file.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3Egit%20clone%20-n%20-b%20%3CBRANCH%3E%20%3CPATH%20to%3D%22%22%20master%3D%22%22%3E%20--depth%201%3C%2FPATH%3E%3C%2FBRANCH%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3Ecd%20%3CREPO%3E%3C%2FREPO%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3Egit%20checkout%20HEAD%20%3CFILE%20in%3D%22%22%20branch%3D%22%22%3E%3C%2FFILE%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%3A%20download%20%22test.txt%22%26nbsp%3B%20file%20from%20the%20%22scripts%22%20branch%20of%20the%20repo%20%22WebSphere%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%224%22%3E%26gt%3Bgit%20clone%20-n%20-b%20scripts%20https%3A%2F%2F%26lt%3B*.com%26gt%3B%2F_git%2FWebSphere%26nbsp%3B--depth%201%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%224%22%3E%26gt%3Bcd%20WebSphere%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20size%3D%224%22%3E%26gt%3Bgit%20checkout%20HEAD%20test.txt%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am new to Azure and created a text file to test with in my Azure repo. I have the command "git" on Windows to download from the Windows server and "wget" or "curl" on Linux. Could somebody give me the syntax to download my test flat file? I am having no luck.  On Windows, I can clone my my repo via the following command:

 

>git clone https://GregSmith0896@dev.azure.com/GregSmith0896/WebSphere/_git/WebSphere

 

On Linux, again I can download the repo with :

 

>wget clone https://GregSmith0896@dev.azure.com/GregSmith0896/WebSphere/_git/WebSphere

 

I would like to just download a specific file in the repo which exists in the branch "scripts" and the file name is "test.txt" 

 

Please let me know. 

 

Thank you. 

 

3 Replies

Azure Repos are based off standard git, and there are many suggestions out there for downloading individual files, for example, you could create an archive:

git archive --format=zip HEAD test.txt -o test.zip

or you could use sparse checkout, which clones the repo, but "hides" certain files you are not interested in, this is an experimental feature, so be careful.

Alternatively, the getBlob Api may be of use, which appears to allow you to download specified files directly from the repo: 

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/blobs/{sha1}?download={download}&fileName={fileName}&$format={$format}&resolveLfs={resolveLfs}&api-version=5.1 

Depending on your use case, you might also consider adding a task to your Azure DevOps Release pipeline to copy the required files to a specified locaton (e.g. AzureBlob File Copy).

steps:
- task: AzureFileCopy@4
  displayName: 'AzureBlob File Copy'
  inputs:
    SourcePath: '$(System.DefaultWorkingDirectory)\Build\site\$(Build.BuildId)\test.txt'
    azureSubscription: 'Visual Studio Enterprise (bc180cfa-8d6b-46bc-97d6-aeaab72b18c4)'
    Destination: AzureBlob
    storage: sitestaging
    ContainerName: '$web'

 

@Scott_Gray Thank you for the information.

 

I am getting the following when I try to download and create a container .. such as a zip file:

 

C:\Users\grsm001\git>git archive --format=zip HEAD test.txt -o test.zip
fatal: not a valid object name: HEAD

 

Doing a Git status shows:

 

C:\Users\grsm001\git>git status
On branch scripts

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
test.zip

nothing added to commit but untracked files present (use "git add" to track)

 

Can you help me with the syntax?

 

Also, I am not versed in using GET. Is there a command I can use this with? 

best response confirmed by grsm001 (New Contributor)
Solution

I was able to find a solution per this thread: https://stackoverflow.com/questions/2466735/how-to-sparsely-checkout-only-one-single-file-from-a-git... - using the -n parameter clone the branch without downloading anything then using the "checkout"  command with "HEAD", you can download a single file.

 

git clone -n -b <branch> <path to master> --depth 1

cd <repo>

git checkout HEAD <file in branch>

 

For example: download "test.txt"  file from the "scripts" branch of the repo "WebSphere"

 

>git clone -n -b scripts https://<*.com>/_git/WebSphere --depth 1

 

>cd WebSphere

 

>git checkout HEAD test.txt