我有一個 GitHub Action,它可以在任何推送到我的倉庫時運行。基本上,它編譯 repo 檔案,提交編譯的檔案,將提交的壓縮壓縮到前一個,然后強制推送到 repo。
從本質上講,這個想法是它無縫地創建一個構建并將其添加到存盤庫中,使其看起來像是原始推送的一部分。
我遇到的唯一問題是git config. 我希望能夠從上次提交中復制user.name和user.email,以便當我的操作執行其提交時,看起來它是由推送的用戶完成的。我知道我可以使用GITHUB_ACTOR環境變數來獲取用戶名,但似乎沒有提供電子郵件的環境變數。GitHub 發現它們不一樣:

那么,我如何設定git config使用上次提交的user.name和user.email?
這是操作的.yaml完整性檔案:
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Git repository
uses: actions/checkout@v2
with:
fetch-depth: 2
- (... step that creates build files ...)
- name: Upload build files to repo
run: |
# Configure git
git config user.name "$GITHUB_ACTOR"
git config user.email "<>"
# Roll back git history to before last commit
# This also adds all changes in the last commit to the working tree
git reset --soft HEAD~1
# Add build files to working tree
git add (build files)
# Commit changes and build files using same commit info as before
git commit -C HEAD@{1}
# Force push to overwrite git history
git push --force
uj5u.com熱心網友回復:
從git 手冊中,您可以通過運行以下命令獲取進行最后一次提交的用戶的用戶名和電子郵件:
git log -n 1 --pretty=format:%an # username
git log -n 1 --pretty=format:
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/352850.html
上一篇:無法使用rebase命令
