git - 如何使用 Azure DevOps 推送到浅克隆

标签 git azure azure-devops yaml azure-yaml-pipelines

我在 Azure DevOps 中有一个存储库,我需要克隆并运行一些 python 代码,然后将结果推回到同一个存储库中。

随着时间的推移,提交历史记录/对象变得越来越大,每次运行所需的时间也越来越长。它看起来像使用 fetchDepth 进行浅克隆可能是最好的选择,但缺乏在 ADO 中实现它的信息,因为它找不到“master”分支。

我收到以下错误:error: pathspec 'master' did not match any file(s) known to git.error: src refspec master does not match any. .

似乎找不到master,我该如何解决这个问题或者我还可以尝试什么?

azure-pipeline.yml

jobs:
- job: Default
  timeoutInMinutes: 60
  pool:
    name: XXX
  workspace:
    clean: all 
  steps:
  - task: DeleteFiles@1
    inputs:
      SourceFolder: 
      Contents: '*'

  - checkout: self
    persistCredentials: false
    clean: true
    displayName: Checkout and clean
    fetchDepth: 3 #Shallow clone

  - task: CmdLine@2
    inputs:
      script: |
        uname -a
        python3 --version
        pip3 install -r requirements.txt
        echo check system
        git clean -d -f
        pwd
        ls -l
        
  - task: CmdLine@2
    inputs:
      script: |
        echo "Running code"
        python3 some_script.py

        git config --global user.email "XXX.com"
        git config --global user.name "XXX"

        git add ../csv/
        git commit -m 'updated files'
        
        git push https://XXX:$(PAT)@XXX.visualstudio.com/XXX master        
     

最佳答案

--深度 克隆操作仅下 pull 一个分支。如果远程存储库包含其他分支,他们将无法在没有路径规范错误的情况下在本地 check out 它们。

您需要显式克隆master分支:

git clone --depth 3 --branch master https://dev.azure.com/test/test/_git/test

阅读here更多信息。

关于git - 如何使用 Azure DevOps 推送到浅克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76036110/

相关文章:

.net - Cosmos DB : Collection exists, 但抛出 410 GONE httpstatus 代码

git - key_load_public : invalid format

git - git 命名空间的用例是什么?

git - linux PS1 - 仅在 git repo 中显示分支名称

azure - 如何使 Azure Pipelines 知道存储库中已有的 YAML 文件?

visual-studio - Visual Studio 正在锁定 .jfm 文件

Azure CLI - 自动化帐户替换内容打破新行

git - 如何永久取消跟踪 git 中的存储库已跟踪的文件?

azure - 如何在没有 session ID 但具有与登录关联的事件的 Kusto 中重新创建 session

Azure Data Lake Storage Gen2 访问 token 生成 - “AADSTS65001 : The user or administrator has not consented to use the application with ID