我想將帶有 Python 腳本的檔案添加并提交到在 GitHub 操作服務器上運行的存盤庫。我通過在我的main.py檔案中運行以下內容來提交檔案:
import os
FILE = './file.txt'
os.system(f'git add {FILE}')
os.system("git commit -m 'update file'")
在 GitHub 操作上,我將 Python 腳本運行為:
- name: Commit file
run: python commit_file.py
但是在 GitHub 操作運行后,repo master 分支上沒有任何腳本提交。
在我的本地機器上,os.system("git commit -m 'update file'")命令運行正常,我可以通過git log命令驗證提交是否存在。在 GitHub 操作上,出現以下錯誤:
Run Commit file
python commit_file.py
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <runner@fv-az112-319.bzi55m0t1ufu323ye4cn5ktith.xx.internal.cloudapp.net>) not allowed
編輯:我又添加了兩行來配置 git 憑據:
os.system('git config --global user.email "[email protected]"')
os.system('git config --global user.name "GitHub Actions"')
現在,警告消失了,但 repo 上仍然沒有提交。
uj5u.com熱心網友回復:
正如錯誤所述,git config當您想使用 github 操作將新檔案提交到存盤庫時,您需要配置用戶電子郵件和名稱。
注意:這些值可以是偽造的、硬編碼的或取決于變數。
您只需要在 python 腳本中的 git add 和 git commit 命令之前添加這 2 個命令列。
此外,您需要git push在腳本末尾執行 a以使檔案在作業流運行結束時出現在存盤庫分支上。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/391825.html
下一篇:更改提交指向的樹
