
WechatIMG1442.jpeg
場景
實現 Git Gitee倉庫自動部署,使用 www-data 用戶拉取代碼時,每次都要設置全局 git 用戶信息。
錯誤
$ cat /var/log/webhooks.log
From gitee.com:xoncology/shjyzxk
* branch zhangyuhai -> FETCH_HEAD
warning: unable to access '/root/.config/git/attributes': Permission denied
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
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: unable to auto-detect email address (got 'www-data@iZuf68boltvbz79cxbsunfZ.(none)')
查看 webhooks 日志文件,返回
fatal: unable to auto-detect email address。
解決
- 查看當前項目 git 信息
$ git config --local -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@gitee.com:xoncology/shjyzxk.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.test.remote=origin
branch.test.merge=refs/heads/test
看到并沒有全局用戶信息。
- 設置全局用戶信息
$ git config --global user.email "you@domain.com" && git config --global user.name "dev"
執(zhí)行上面命令設置后,還是不能成功拉取。
- 直接替換全局用戶信息
$ git config --replace-all user.email "you@domain.com" && git config --replace-all user.name "github_username"
- 再次查看當前項目 git 信息
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@gitee.com:xoncology/shjyzxk.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.test.remote=origin
branch.test.merge=refs/heads/test
user.email=you@domain.com
user.name=github_username
看到已成功返回全局用戶信息,再次嘗試提交代碼,服務器可以自動拉取。