部署自动使用commit
一、修改你的 workflow
把这一行:
git commit -m "自动化部署完成"
改成:
git commit -m "${{ github.event.head_commit.message }}"
修改后的关键部分
- name: Deploy to Blog Repository
run: |
git clone https://${{ secrets.GH_TOKEN_BLOG }}@github.com/baidu/wiki_wangyongjie_com.git wiki
cd wiki
git config --global user.email "baidu@gmail.com"
git config --global user.name "baidu"
rm -rf ./*
cp -r ../site/* .
git add .
git commit -m "${{ github.event.head_commit.message }}"
git push
二、效果是什么
假设你本地提交:
git commit -m "新增 AI Agent 文章"
部署仓库的 commit 就会变成:
新增 AI Agent 文章
而不是:
自动化部署完成
三、再推荐一个更专业的写法(带 commit hash)
很多 CI 会这样写,方便追溯:
git commit -m "${{ github.event.head_commit.message }} (auto deploy)"
或者:
git commit -m "${{ github.event.head_commit.message }} - ${{ github.sha }}"
示例:
新增 AI Agent 文章 - 7f3c9b1
四、如果 push 多个 commit 会怎样
注意:
github.event.head_commit.message
只会取 最后一个 commit。
例如:
commit1
commit2
commit3
git push
部署 message 是:
commit3
五、最推荐的博客写法
我一般建议:
git commit -m "${{ github.event.head_commit.message }} [deploy]"
部署仓库会显示:
新增 AI Agent 文章 [deploy]
很清晰。
六、再给你一个更高级的小技巧(很多人不知道)
你还可以把 作者也同步过去:
git commit \
--author="${{ github.event.head_commit.author.name }} <${{ github.event.head_commit.author.email }}>" \
-m "${{ github.event.head_commit.message }}"
这样部署仓库显示的作者也是:
JakeWang
而不是 CI 机器人。
✅ 总结
把:
git commit -m "自动化部署完成"
改成:
git commit -m "${{ github.event.head_commit.message }}"
即可同步 commit message。
如果你愿意,我可以顺便帮你 把这整套 GitHub Actions 改成更现代的写法(2026推荐版),能解决几个你这份 workflow 里的潜在问题,比如:
- commit 空内容导致 CI 失败
- clone 仓库权限问题
- commit message 同步
- 自动跳过空部署
很多人现在都用这套结构。