我在 AWS EC2 上使用 Ubuntu 22.04,git 版本 2.34.1
以下是我的~/.gitconfig
文件:
[credential "https://github.com"]
helper =
helper = !/usr/bin/gh auth git-credential
[credential "https://gist.github.com"]
helper =
helper = !/usr/bin/gh auth git-credential
[safe]
directory = /var/www/html/wix
directory = /var/www/html/wix-native-app
[user]
name = JXX XXXha
email = jXXXX0@gmail.com
signingkey = 8XXXXXXXXXXX1
[commit]
gpgsign = true
但是,当我尝试提交时,出现以下错误:ubuntu@ip-172-31-46-106:/var/www/html/wix-native-app$ sudo git commit
Author identity unknown
*** 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: no email was given and auto-detection is disabled
但正如我的 .gitconfig
中所见文件、用户名和电子邮件已设置。在配置中是否还有其他事情要做才能提交工作?
最佳答案
您正在使用 sudo
执行 git即作为用户 root
.所以 git 会在 /root/.gitconfig
中寻找配置。 , 当您在 ~/.gitconfig
中设置配置时即在您的非特权用户的主路径中。
你有两个选择:
/var/www/html/wix-native-app
的权限和/或所有权这样您的非特权用户 ubuntu
有权读取和写入此路径。确保包括 -R
给您的chmod
/chgrp
命令将更改应用到所有文件和子文件夹。优点:
/var/www/html/
的不同子文件夹,您可以将写入权限仅分配给他们负责的文件夹。 ~/.gitconfig
至/root/.gitconfig
所以如果你运行 sudo'ed,git 会找到配置。缺点:
关于Git不使用全局配置文件中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72525675/