You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Github Actions工作流执行成功但无分支提交问题求助

问题:Github Actions工作流执行成功但分支无新提交

我配置了Github Actions工作流,目标是把better-page分支的文件复制到simplified目录,再将该目录内容同步到gh-pages分支。工作流显示执行成功,但两个分支均未生成新提交,无法定位问题。

原工作流代码

name: Copy files to another branch

on:
    push:
        branches:
            - better-page
    workflow_dispatch:

permissions:
    contents: write
    pages: write
    id-token: write

concurrency:
    group: "pages"
    cancel-in-progress: false

jobs:
    copy:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout better-page
              uses: actions/checkout@v2
              with:
                  ref: better-page

            - name: Copy files 1
              run: |
                  git config --global user.name "GitHub Actions"
                  git config --global user.email "action@github.com"
                  git fetch origin better-page:better-page --update-head-ok
                  # rsync -r --exclude=.git --exclude=.github --exclude=about-me --exclude=node_modules --exclude=simplified . simplified/
                  find . -mindepth 1 -maxdepth 1 ! -name 'simplified' -exec cp -r {} simplified \;
                  git add .
                  git diff-index --quiet HEAD ||  git commit -am "create simplified directory"  # commit to the repository (ignore if no modification)
                  git push origin better-page # push to remote branch

            - name: Checkout gh-pages
              uses: actions/checkout@v2
              with:
                  ref: gh-pages
                  path: gh-pages

            - name: Copy files 2
              run: |
                  git config --global user.name "GitHub Actions"
                  git config --global user.email "action@github.com"
                  git fetch origin gh-pages:gh-pages --update-head-ok
                  git archive --format tar better-page simplified | tar x -vf -
                  git add .
                  git diff-index --quiet HEAD ||  git commit -am "copy files from better-page"  # commit to the repository (ignore if no modification)
                  git push origin gh-pages # push to remote branch

执行警告

Annotations
2 warnings
copy
Node.js 12 actions are deprecated. Please update the following actions to use Node.js 16: actions/checkout@v2. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.
copy
The process '/usr/bin/git' failed with exit code 128

执行日志

succeeded 2 hours ago in 9s
Search logs
1s
Current runner version: '2.303.0'
Operating System
Runner Image
Runner Image Provisioner
GITHUB_TOKEN Permissions
Secret source: Actions
Prepare workflow directory
Prepare all required actions
Getting action download info
Download action repository 'actions/checkout@v2' (SHA:ee0669bd1cc54295c223e0bb666b733df41de1c5)
Complete job name: copy
2s
Run actions/checkout@v2
Syncing repository: quincynyan/quincynyan
Getting Git version info
Temporarily overriding HOME='/home/runner/work/_temp/c8b9627a-19c0-4ab3-99f7-115b756d1c6d' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/quincynyan/quincynyan
Deleting the contents of '/home/runner/work/quincynyan/quincynyan'
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
Determining the checkout info
Checking out the ref
/usr/bin/git log -1 --format='%H'
'bf3cdc18f11643fb9a03e2a6eb5e2135db12cfc1'
1s
Run git config --global user.name "GitHub Actions"
[better-page 1908b12] create simplified directory
 1 file changed, 1 insertion(+), 1 deletion(-)
remote: Resolving deltas:   0% (0/1)        
remote: Resolving deltas: 100% (1/1)        
remote: Resolving deltas: 100% (1/1), completed with 1 local object.        
To https://github.com/quincynyan/quincynyan
   bf3cdc1..1908b12  better-page -> better-page
0s
Run actions/checkout@v2
Syncing repository: quincynyan/quincynyan
Getting Git version info
Copying '/home/runner/.gitconfig' to '/home/runner/work/_temp/8e9a2c66-c9d9-4090-9087-a01df1ad8673/.gitconfig'
Temporarily overriding HOME='/home/runner/work/_temp/8e9a2c66-c9d9-4090-9087-a01df1ad8673' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/quincynyan/quincynyan/gh-pages
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
Determining the checkout info
Checking out the ref
/usr/bin/git log -1 --format='%H'
'fed1db795cff8ccbaa364f6121a6f7f6883f0b7e'
0s
Run git config --global user.name "GitHub Actions"
From https://github.com/quincynyan/quincynyan
 * [new branch]      gh-pages   -> gh-pages
 * [new branch]      gh-pages   -> origin/gh-pages
simplified/
warning: adding embedded git repository: gh-pages
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> gh-pages
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached gh-pages
hint: 
hint: See "git help submodule" for more information.
[better-page 33fc0c8] copy files from better-page
 1 file changed, 1 insertion(+)
 create mode 160000 gh-pages
Everything up-to-date
0s
Post job cleanup.
/usr/bin/git version
git version 2.40.0
Copying '/home/runner/.gitconfig' to '/home/runner/work/_temp/cb46980b-3cf9-44eb-8849-acc56b031201/.gitconfig'
Temporarily overriding HOME='/home/runner/work/_temp/cb46980b-3cf9-44eb-8849-acc56b031201' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/quincynyan/quincynyan/gh-pages
/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
http.https://github.com/.extraheader
/usr/bin/git config --local --unset-all http.https://github.com/.extraheader
/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :"
0s
Post job cleanup.
/usr/bin/git version
git version 2.40.0
Copying '/home/runner/.gitconfig' to '/home/runner/work/_temp/794b3a8d-22e2-4378-97b6-583b0ae59af0/.gitconfig'
Temporarily overriding HOME='/home/runner/work/_temp/794b3a8d-22e2-4378-97b6-583b0ae59af0' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/quincynyan/quincynyan
/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
/usr/bin/git submodule foreach --recursive sh -c "git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :"
fatal: No url found for submodule path 'gh-pages' in .gitmodules
Warning: The process '/usr/bin/git' failed with exit code 128
0s
Cleaning up orphan processes

问题分析

  1. 核心错误:分支操作上下文错误
    第二个复制步骤没有切换到gh-pages目录,所有git操作都在better-page分支执行。git add .把gh-pages目录(另一个独立git仓库)当成子模块提交到了better-page分支,而gh-pages分支本身没有任何变更,导致git push origin gh-pages显示"Everything up-to-date"。
  2. actions/checkout版本过时
    使用的actions/checkout@v2依赖Node.js 12,已被废弃,会导致警告。
  3. 不必要的权限配置
    配置了pages和id-token权限,但实际只是同步分支,不需要这些权限。
  4. 文件复制逻辑不严谨
    原find命令没有排除.git、.github等不必要的目录,可能复制冗余内容。

修复后的工作流代码

name: Copy files to another branch

on:
    push:
        branches:
            - better-page
    workflow_dispatch:

permissions:
    contents: write

concurrency:
    group: "pages"
    cancel-in-progress: false

jobs:
    copy:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout better-page
              uses: actions/checkout@v4
              with:
                  ref: better-page
                  fetch-depth: 0 # 拉取全量历史,避免git archive操作失败

            - name: Update simplified directory on better-page
              run: |
                  git config --local user.name "GitHub Actions"
                  git config --local user.email "action@github.com"
                  # 清空旧的simplified目录,避免残留文件
                  rm -rf simplified
                  mkdir simplified
                  # 复制指定范围的文件到simplified
                  find . -mindepth 1 -maxdepth 1 \
                      ! -name 'simplified' \
                      ! -name '.git' \
                      ! -name '.github' \
                      ! -name 'about-me' \
                      ! -name 'node_modules' \
                      -exec cp -r {} simplified/ \;
                  # 仅在有变更时提交
                  if ! git diff-index --quiet HEAD; then
                      git add simplified/
                      git commit -m "Update simplified directory"
                      git push origin better-page
                  fi

            - name: Checkout gh-pages branch
              uses: actions/checkout@v4
              with:
                  ref: gh-pages
                  path: gh-pages
                  fetch-depth: 0

            - name: Sync simplified content to gh-pages
              run: |
                  cd gh-pages # 切换到gh-pages分支目录
                  git config --local user.name "GitHub Actions"
                  git config --local user.email "action@github.com"
                  # 清空gh-pages现有内容(保留.git目录)
                  rm -rf * .[^.]* 2>/dev/null || true
                  # 从远程better-page分支拉取simplified目录内容
                  git archive origin/better-page:simplified | tar x -vf -
                  # 仅在有变更时提交
                  if ! git diff-index --quiet HEAD; then
                      git add .
                      git commit -m "Sync files from better-page/simplified"
                      git push origin gh-pages
                  fi

修复说明

  • 切换分支操作上下文:在同步gh-pages时,先cd gh-pages进入目标分支目录,确保所有git操作都作用于gh-pages分支。
  • 升级checkout版本:改用actions/checkout@v4,解决Node.js过时警告。
  • 优化文件复制逻辑:明确排除不需要的目录,先清空旧目录再复制,避免残留文件。
  • 精准提交判断:用if ! git diff-index --quiet HEAD替代原逻辑,更清晰判断是否需要提交。
  • 移除冗余权限:只保留contents: write权限,符合实际需求。
  • 使用远程分支内容:直接从远程better-page分支拉取simplified内容,避免本地分支冲突。

内容的提问来源于stack exchange,提问作者DavidNyan10

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 15:24:55