如何检查最后 2 次推送提交之间的差异

How to check the diff between the last 2 pushed commits

所以,我有一个 GitHub 工作流,它在推送时运行并检查特定目录中的更改并在有更改时运行脚本。但是,对于当前的实现 (git diff HEAD^ HEAD),它只检查最后 2 次提交之间的差异。推送超过 1 个提交是完全有可能的,所以我正在寻找一种方法来比较最后 2 个 pushed 提交。

如果有人能帮助我,那就太棒了!

您可以使用以下内容:

on: 
  push:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          # checkout full tree
          fetch-depth: 0
      - run: |
          git diff ${{github.event.before}} ${{github.sha}}

根据 the docs on the github context and the docs on the push webhook event data {{github.event.before}} 被推送前的提交 SHA 替换。 {{github.sha}}{{github.event.after}} 被推送的最新提交的 SHA 替换。