如何在github操作中运行gitdiff
我得到这个:
Command failed: git diff --name-only HEAD^..HEAD
fatal: ambiguous argument 'HEAD^..HEAD': unknown revision or path not in the working tree.
我想git diff --name-only HEAD^..HEAD在我的分支中运行以获取已更改文件的列表。它在本地工作,但不在 GitHub 操作上。我必须做什么?
我的代码是这样的:
name: build
on:
push:
branches:
- main
jobs:
run:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Configure Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Install dependencies
run: yarn install
- name: Publish file changes to Slack
# HERE I run `git diff` in node.js process
run: "SLACK_TOKEN=${{ secrets.GITHUB_TOKEN }} npx ts-node scripts/publishSlackUpdate"
- name: Build TOC
run: make toc
- name: Commit build changes
uses: EndBug/add-and-commit@v7
with:
author_name: Docs Builder
author_email: docs@mysite.com
message: 'Updated build'
add: '*.md'
回答
如果您查看actions/checkout@v2操作的文档,您会看到默认情况下它执行带有单个修订的浅层克隆:
# Number of commits to fetch. 0 indicates all history for all branches and tags.
# Default: 1
fetch-depth: ''
因为它只获取一个修订版,所以没有HEAD^.
您可以通过fetch-depth在结帐操作上设置选项来解决此问题。将其设置为0将获取整个历史记录;或者,对于您正在做的事情,您可能只需将其设置为2:
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 2
- That would be "Setting it to 0 will fetch the entire history"