.gitconfig即使我';您的配置正确吗

.gitconfig即使我';您的配置正确吗,git,Git,我已经正确地配置了~/.gitconfig,如下所示 git config --global user.name "yuzhi" git config --global user.email "1762266120@qq.com" 结果如下 saber@debian:~$ git config -l user.name=yuzhi user.email=1762266120@qq.com core.editor=vim color.ui=true sa

我已经正确地配置了
~/.gitconfig
,如下所示

git config --global user.name "yuzhi"
git config --global user.email "1762266120@qq.com"
结果如下

saber@debian:~$ git config -l
user.name=yuzhi
user.email=1762266120@qq.com
core.editor=vim
color.ui=true

saber@debian:~$ git config --global -l
user.name=yuzhi
user.email=1762266120@qq.com
core.editor=vim
color.ui=true
让我困惑的是,当我提交git时,它不起作用

saber@debian:~/ics2020$ sudo git commit

*** 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 'root@debian.(none)')
但是当我在下面的命令之后发出
git commit
时,它就可以工作了

git config --local user.name "yuzhi"
git config --local user.email "1762266120@qq.com"
顺便说一句: 我正在vmware上运行
Debian-10.8
。 和
git==2.20.1
。 与我的问题类似,但我不知道如何在linux中解决。

您可以将配置(假设最近有足够的Git,如果没有:)与:

git config --show-origin --show-scope -l
sudo git config --show-origin --show-scope -l
您将清楚地看到路径上的差异(
/home/saber/
/root
),解释为什么您看不到相同的配置。
也就是说,正如所评论的,不要将
sudo
用于常规命令,如
git

saber@debian:~/ics2020$ sudo git commit

*** 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 'root@debian.(none)')

如中所述,如果存储库最初是使用
sudo
(生成由
root
拥有的文件)创建的,则第一次提交(由普通用户完成)将触发:

saber@debian:~/ics2020$ git commit 
fatal: Unable to create '/home/saber/ics2020/.git/index.lock': Permission denied.
这意味着您需要恢复适当的所有权:

cd ~/ics2020
sudo chown -R $(id -u saber):$(id -g saber)
然后,一个简单的提交(没有sudo)将起作用。

您可以比较(假设最近有足够的Git,如果没有:)配置:

git config --show-origin --show-scope -l
sudo git config --show-origin --show-scope -l
您将清楚地看到路径上的差异(
/home/saber/
/root
),解释为什么您看不到相同的配置。
也就是说,正如所评论的,不要将
sudo
用于常规命令,如
git

saber@debian:~/ics2020$ sudo git commit

*** 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 'root@debian.(none)')

如中所述,如果存储库最初是使用
sudo
(生成由
root
拥有的文件)创建的,则第一次提交(由普通用户完成)将触发:

saber@debian:~/ics2020$ git commit 
fatal: Unable to create '/home/saber/ics2020/.git/index.lock': Permission denied.
这意味着您需要恢复适当的所有权:

cd ~/ics2020
sudo chown -R $(id -u saber):$(id -g saber)

然后,一个简单的提交(不带
sudo
)将起作用。

当您使用
sudo
时,本地用户不是
saber
。sudo用户有自己的全局配置。正如日志所说,sudo用户是
root
。如果所有用户都只属于您,您可以使用
git config--system
。同样值得一提的是,您不应该像
sudo
那样使用
git
命令。如果是这样,说明您做错了。当您使用
sudo
时,本地用户不是
saber
。sudo用户有自己的全局配置。正如日志所说,sudo用户是
root
。如果所有用户都只属于您,您可以使用
git config--system
。同样值得一提的是,您不应该像
sudo
那样使用
git
命令。如果是这样,你就做错了。你是对的!!!非常感谢!但是它让我对选项
--show scope
有点困惑saber@debian:~/ics2020$git config--show origin--show scope-l错误:未知选项show scope`souther,我删除它并发出`git config--show origin-l sudo config--show origin-l`第一个cammond show`file:/home/saber/.gitconfig user.name=yuzhi file:/home/saber/.gitconfig user.email=1762266120@qq.com`但是第二个的输出没有user.name和user.email…@Arthur
--show scope
表示最小Git 2.26(2020年第一季度:)。您可以使用ppa更新git:。另一个问题:当发出<代码>git提交时,它会显示<代码>saber@debian:~/ics2020$git commit fatal:无法创建“/home/saber/ics2020/.git/index.lock”:权限被拒绝。它需要
sudo
…因此我按如下方式解决它。
saber@debian:~/ics2020$sudo git config--全局user.name“玉芝”saber@debian:~/ics2020$sudo git config--global user.email“1762266120@qq.com" saber@debian:~/ics2020$sudo git config--global core.editor vimsaber@debian:~/ics2020$sudo git config--global color.ui true
我不知道为什么我要求以
sudo
的形式执行它!@Arthur可能是因为存储库最初是用
sudo
创建的,文件的所有者是
root
。使用
sudo
来恢复正确的所有权:
cd/path/to/repo;sudo chown-R$(id-u saber):$(id-g saber)
。然后再次尝试提交(不使用
sudo
)@Arthur太棒了!我编辑了答案,以反映错误及其解决方案,以提高可见性。你是对的!!!非常感谢!但这让我对选项
--show scope
有点困惑saber@debian:~/ics2020$git config--show origin--show scope-l错误:未知选项show scope`e`git config--show origin-l sudo config--show origin-l`第一个cammond显示`file:/home/saber/.gitconfig user.name=yuzhi file:/home/saber/.gitconfig user.email=1762266120@qq.com`但是第二个的输出没有user.name和user.email…@Arthur
--show scope
表示最低2.26吉特(2020年第1季度:)。您可以使用ppa更新git:。另一个问题:当发出<代码>git提交时,它会显示<代码>saber@debian:~/ics2020$git commit fatal:无法创建“/home/saber/ics2020/.git/index.lock”:权限被拒绝。它需要
sudo
…因此我按如下方式解决它。
saber@debian:~/ics2020$sudo git config--全局user.name“玉芝”saber@debian:~/ics2020$sudo git config--global user.email“1762266120@qq.com" saber@debian:~/ics2020$sudo git config--global core.editor vimsaber@debian:~/ics2020$sudo git config--global color.ui true
我不知道为什么我要求以
sudo
的形式执行它!@Arthur可能是因为存储库最初是用
sudo
创建的,文件的所有者是
root
。使用
sudo
来恢复正确的所有权:
cd/path/to/repo;sudo chown-R$(id-u saber):$(id-g saber)
。然后再次尝试提交(不使用
sudo
)@Arthur Great!我编辑了答案以反映错误及其解决方案,以获得更多的可见性。