我正在尝试查找 GitHub 操作中一个分支与另一个分支分离的提交的 SHA。
在本地,我可以通过运行 git merge-base <commit> <commit>
来实现这一点.我正在尝试在工作流程中实现相同的目标。
我有以下 workflow.yaml
:
name: "Find common ancestor"
on:
pull_request:
branches:
- master
jobs:
find:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Find common ancestor
run: git merge-base "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF"
当打开分支“dev”到“master”的 pull 请求时工作流运行时,工作流报告以下错误:
2021-08-14T19:17:04.5732118Z fatal: Not a valid object name dev
我所有的research指向需要设置获取深度。我知道如果不将 fetch-depth 设置为 0,只会获取浅层克隆。不幸的是,即使将 fetch-depth 设置为 0,工作流也无法找到必要的引用,而且我没有想法。
有谁知道为什么 merge-base 不能识别引用,或者知道寻找共同祖先的替代方法?
编辑:
正在运行 git branch -a
, 我发现 refs 前面有 remote/origin/*
,这解释了为什么在调用 merge-base
时找不到它们.为什么 checkout 后无法进入本地分行?
最佳答案
FindCommon:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Find common ancestor
env:
BASE_BRANCH: ${{ github.base_ref }}
run: git merge-base --fork-point origin/$BASE_BRANCH
对我有用。 👍
关于git - 在 GitHub Actions 中查找 pull 请求的共同祖先,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68786435/