简体   繁体   English

如何将 Git LFS 与 Azure Repos 和管道一起使用

[英]How to use Git LFS with Azure Repos and Pipelines

I have a project using Git LFS in Azure Repos with several binary image files being checked in using Git LFS.我有一个在 Azure Repos 中使用 Git LFS 的项目,其中几个二进制图像文件正在使用 Git LFS 签入。 When my Azure Pipelines build performs a git pull , the image files are not pulled from Git LFS and I am left with several zero byte image files.当我的 Azure Pipelines 构建执行git pull时,图像文件不会从 Git LFS 中拉出,我留下了几个零字节图像文件。

I'm using a custom self-hosted Azure Pipelines build server which has a recent version of Git LFS installed on it:我正在使用自定义的自托管 Azure Pipelines 构建服务器,它安装了最新版本的 Git LFS:

PS C:\rehan> git lfs --version                                                                                     git-lfs/2.7.2 (GitHub; windows amd64; go 1.12.2; git 08a08ae0)

I've tried adding steps to perform a git lfs install but that doesn't help.我已经尝试添加步骤来执行git lfs install ,但这没有帮助。 When I manually perform a git lfs pull after logging on to the build server, the files are downloaded correctly.当我在登录构建服务器后手动执行git lfs pull时,文件已正确下载。 When I run git lfs pull as a build step in my Azure Pipeline, I get the following error:当我在 Azure 管道中运行git lfs pull作为构建步骤时,出现以下错误:

fatal: could not read Username for 'https://foo.visualstudio.com': terminal prompts disabled
batch response: Git credentials for https://foo.visualstudio.com/Bar/_git/Bar not found.
error: failed to fetch some objects from 'https://foo.visualstudio.com/Bar/_git/Bar.git/info/lfs'
Downloading LFS objects:   0% (0/1), 0 B | 0 B/s                                
##[error]PowerShell exited with code '1'.

You have to use https for lfs to work with Azure Devops and you have to do LFS checkout when doing the builds:您必须为 lfs 使用 https 才能与 Azure Devops 一起使用,并且在进行构建时必须进行 LFS 检出:

steps:
- checkout: self  # self represents the repo where the initial Pipelines YAML file was found
  lfs: true

if you are using a UI wizard there is a checkbox to checkout lfs如果您使用的是 UI 向导,则有一个复选框可以检查 lfs

https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#checkout https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#checkout
https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/pipeline-options-for-git?view=azure-devops#checkout-files-from-lfs https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/pipeline-options-for-git?view=azure-devops#checkout-files-from-lfs

Unfortunately @4c74356b41's answer did not work for me.不幸的是,@4c74356b41 的回答对我不起作用。 I have the same issue as @Haroon:我和@Haroon 有同样的问题

I configured the checkout step with lfs but the files stayed text files with hashes.我使用lfs配置了checkout步骤,但文件仍然是带有哈希的文本文件。

The solution was to manually run git lfs fetch and git lfs pull解决方案是手动运行git lfs fetchgit lfs pull

  steps:
  - checkout: self
    lfs: true

  - script: |
     git lfs fetch
     git lfs pull
    displayName: git-lfs

I think that the error is pretty straight forward.我认为这个错误很直接。 You haven't provided git credentials in your pipepline.您尚未在管道中提供 git 凭据。

And more important, can I ask why are you using git for binaries?更重要的是,我能问一下你为什么要使用 git 来处理二进制文件吗? How do you intend to have version control over something that git doesn't understand?你打算如何对 git 不理解的东西进行版本控制? By that I mean, how do you intend to use features like diff and merge on binary files?我的意思是,您打算如何在二进制文件上使用 diff 和 merge 等功能?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM