Git使用了错误的身份(.ssh / config文件没有被读取?)

6
我在公司工作时使用gitlab.com,在个人工作中使用github.com。 我阅读了很多关于身份问题的主题和线程,但我仍然不明白为什么它对我不起作用。 我有一个如下所示的“~/.ssh/config”文件。
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/perso_id_rsa

Host gitlab
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_rsa

还有一个主文件~/.gitconfig

[user]
    email = my_company_address
    name = my_company_name

[includeIf "gitdir:~/Workspace/perso"]
    path = ~/Workspace/perso/.gitconfig

还有一个~/Workspace/perso/.gitconfig

[user]
    email = my_perso_email
    name = my_pseudo

当我从~/Workspace/perso/my_perso_project提交代码时,提交者信息显示为我的公司邮箱地址(该提交成功地推送到了Github)。请问有人能够提供帮助吗?谢谢。

“.ssh” 的内容与创建新提交完全无关。 “user.name” 等内容与进行 ssh 推送/提取操作完全无关。 “includeIf” 指令需要现代 Git;您使用的是哪个 Git 版本? - torek
我正在使用 git 2.17.1。 - ValLeNain
2个回答

4
你的 includeif 是错误的。 `gitdir:~/Workspace/perso` 不是 `.git` 目录,也没有搜索标记。有关 includeif 的更多信息,请参见 `git config` 文档。
如果模式以 `/` 结尾,则会自动添加 `**` 。例如,模式 `foo/` 变成 `foo/**`。换句话说,它匹配“foo”和其中所有内容,递归地遍历整个目录树。
要么命名你正在检查的特定 git 目录,要么告诉 Git 你的意思是子树中的任何 git 目录。
[includeIf "gitdir:~/Workspace/perso/.git"]
        path = ~/Workspace/perso/.gitconfig

或者

[includeIf "gitdir:~/Workspace/perso/**"]
        path = ~/Workspace/perso/.gitconfig

或者

[includeIf "gitdir:~/Workspace/perso/"]
        path = ~/Workspace/perso/.gitconfig

0

IncludeIf 在 Git 2.17.1 中得到支持(它在2.13中被引入

正如评论所述,~/.ssh/config 仅用于身份验证,而不是作者身份。

我会进入 ~/Workspace/perso/my_perso_projec 并执行:

git config --list --show-origin

这样,你就知道哪个文件将设置user.email
最后显示的覆盖其他的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接