简体   繁体   English

git 子模块更新 --remote --merge 产生致命:需要单个修订

[英]git submodule update --remote --merge yields fatal: Needed a single revision

Suppose I have a repo with the following submodule structure:假设我有一个具有以下子模块结构的仓库:

[submodule "themes/sanskrit-documentation-theme-hugo"]
    path = themes/sanskrit-documentation-theme-hugo
    url = https://github.com/sanskrit-coders/sanskrit-documentation-theme-hugo.git
    update = merge
[submodule "content"]
    path = content
    url = https://github.com/vvasuki/kAvyam.git
    branch = content
    update = merge

While checking out this repository in the cloud, I would like all the submodules to be updated to the latest commit from the respective remote branches.在云中查看此存储库时,我希望将所有子模块更新为来自相应远程分支的最新提交。

In github actions, if I run (example here with workflow file ) git submodule update --remote --merge , I get this error fatal: Needed a single revision .在 github 动作中,如果我运行( 此处工作流文件为例) git submodule update --remote --merge ,我得到这个错误fatal: Needed a single revision What gives?是什么赋予了? Is there an alternative?有替代方案吗?

Alternatives tried尝试过的替代品

git submodule foreach "(git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master); git pull)&" - this works on my computer, but not in github actions (master branch is wrongly checked out for submodule content). git submodule foreach "(git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master); git pull)&" - 这适用于我的计算机,但不适用于 ZBF211547B3 actionsmaster(被错误地检出子模块内容)。

Trouble seems to have been with actions/checkout step.问题似乎与操作/结帐步骤有关。 The following worked:以下工作:

Disabling submodules initialization in the action as below在如下操作中禁用子模块初始化

    - name: Checkout
      uses: actions/checkout@master
      with:
        submodules: false

Manual updation:手动更新:

    - name: Update submodules
      if: ${{ github.event_name != 'pull_request'}}
      run: |
        set -o xtrace
        git submodule update --init --recursive
        git submodule update --remote --merge --recursive

You are cloning with a depth of 1 and then run the git pull --recurse-submodules command with --depth 1 .您正在使用深度1进行克隆,然后使用--depth 1运行git pull --recurse-submodules命令。 I would suggest to replace most of that workflow with something along the lines of this that I personally use a lot as well too.我建议用我个人也经常使用的类似方法来替换大部分工作流程。

name: Submodule Update

on:
  push:
    branches: [ main ]
    tags:
    - '*'
  schedule:
  - cron: '20 * * * *'

jobs:
  submodule-update:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@main
      with:
        # we need the submodules.
        submodules: recursive

    - name: Update submodule.
      run: git submodule update --remote

    # this creates a commit with the worker's working tree changes (in this case from the submodule update command) and pushes it to a branch named "app/updated-submodules".
    - name: Create Pull Request
      id: cpr
      uses: peter-evans/create-pull-request@main
      with:
        # you will need an Personal Access Token if you want workflow runs to trigger inside of the created pull request created by this workflow.
        token: ${{ secrets.GITSYNC_TOKEN }}
        commit-message: Update submodules.
        # do not change it does not change anything other than the github-actions account basically pushes it.
        committer: GitHub <noreply@github.com>
        author: any user here <any user's noreply github email here>
        signoff: true
        branch: app/updated-submodules
        base: main
        # delete branch after merge.
        delete-branch: true
        title: 'Update submodules.'
        body: |
          Update submodules
          - Auto-generated by [create-pull-request][1]

          [1]: https://github.com/peter-evans/create-pull-request
        draft: false

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

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