【问题标题】:Access repo branches in Github Action在 Github Action 中访问 repo 分支
【发布时间】:2020-10-01 16:30:27
【问题描述】:

我想在 Github Action 中执行分支比较。但是git branch 返回类似ls 的结果,而不是文件列表!

run: echo $(git branch)

外壳:/bin/bash -e {0}

LICENSE README.md index.html node_modules package-lock.json package.json src yarn.lock(HEAD 在 pull/29/merge 时分离)

这是为什么呢?坏了吗?

如何在分支上执行 git 命令?

【问题讨论】:

    标签: git continuous-integration git-branch github-actions


    【解决方案1】:

    git branch 返回一个列表,其中当前分支标有星号*。然后echo(实际上是shell)扩展了星号。

    要么处理git branch 的输出并删除*,要么使用git for-each-ref refs/heads/

    更新git clone --depthimplies--single-branch。获取其他分支:

    git remote set-branches origin '*'
    git fetch
    

    git shallow clone (clone --depth) misses remote branches

    【讨论】:

    • 谢谢!这回答了为什么要添加文件列表。但是我仍然不知道为什么我看不到其他分支。顺便说一句,我也可以按照文档的建议将fetch-depth: 0 添加到结帐中,但这无济于事。
    • "我仍然不知道为什么我看不到其他分支。" 很可能是因为 Github Action 没有获取它们。请注意git clone --depth 隐含--single-branch
    • 正确。如果您可以将git fetch 添加到运行中,我将验证答案
    猜你喜欢
    • 2022-01-17
    • 2021-12-05
    • 1970-01-01
    • 2023-01-24
    • 2020-01-26
    • 1970-01-01
    • 2020-01-08
    • 2021-07-23
    • 2021-12-29
    相关资源
    最近更新 更多