Git不使用全局配置文件中的用户

标签 git amazon-web-services ubuntu

我在 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命令将更改应用到所有文件和子文件夹。
    优点:
  • 您不需要特权用户来更改 Web 服务器的内容。有权更改内容的用户不会获得篡改服务器配置的权限。
  • 您可以使用组将权限分配给多个用户。
  • 如果您有不同的用户负责 /var/www/html/ 的不同子文件夹,您可以将写入权限仅分配给他们负责的文件夹。

  • 复制您的 ~/.gitconfig/root/.gitconfig所以如果你运行 sudo'ed,git 会找到配置。
    缺点:
  • 在大多数情况下,您不应将更改 Web 服务器内容视为需要特权帐户的管理任务。

  • 关于Git不使用全局配置文件中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72525675/

    相关文章:

    php - 将多个文件上传到 Amazon S3

    node.js - 如何在 Chromebook 上安装 Cloud9 本地 IDE

    amazon-web-services - AWS ssh 公钥被拒绝

    linux - Git 凭证助手不起作用

    git - 仅 merge git 分支中的增量更改

    git - Jenkins :gitlabCommitStatus 不工作

    php - Elastic Beanstalk 在启用 ZipArchive 的情况下编译 php

    git - 如何在 visualstudio.com 的命令行上输入 git 凭据?

    android - import com.amazonaws 无法解析

    ubuntu - .htaccess 位于 ubuntu apache2 的什么位置?