[英]Git uses the wrong identity (.ssh/config file not read ?)
I use gitlab.com for my company work, and github.com for my personal work.我在公司工作中使用 gitlab.com,在个人工作中使用 github.com。 I've read lots of threads, lots of topics about identity problem and yet, I'm still not able to understand why it's not working from me.
我已经阅读了很多线程,很多关于身份问题的主题,但是,我仍然无法理解为什么它对我不起作用。
I have a ~/.ssh/config
file as follow我有一个
~/.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
And a master ~/.gitconfig
和一个主
~/.gitconfig
[user]
email = my_company_address
name = my_company_name
[includeIf "gitdir:~/Workspace/perso"]
path = ~/Workspace/perso/.gitconfig
And a ~/Workspace/perso/.gitconfig
还有一个
~/Workspace/perso/.gitconfig
[user]
email = my_perso_email
name = my_pseudo
When I'm making commits from my perso project in ~/Workspace/perso/my_perso_project, the commit author is my company address (the commit is pushed to github without problem).当我从 ~/Workspace/perso/my_perso_project 中的 perso 项目提交时,提交作者是我的公司地址(提交毫无问题地推送到 github)。
Can somebody help ?有人可以帮忙吗?
Thanks谢谢
Your includeif is wrong.你的 includeif 是错误的。
gitdir:~/Workspace/perso
is not the .git
dir, and doesn't have the search flag. gitdir:~/Workspace/perso
不是.git
目录,并且没有搜索标志。 See the git config
docs for includeif,请参阅
git config
文档以了解 includeif,
If the pattern ends with
/
,**
will be automatically added.如果模式以
/
结尾,**
将自动添加。 For example, the patternfoo
/ becomesfoo/**
.例如,模式
foo
/ 变为foo/**
。 In other words, it matches "foo" and everything inside, recursively.换句话说,它递归地匹配“foo”和里面的所有内容。
Either name the specific git dir you're checking for or tell Git you mean any git dir in that entire subtree:要么命名您正在检查的特定 git 目录,要么告诉 Git 您的意思是整个子树中的任何 git 目录:
[includeIf "gitdir:~/Workspace/perso/.git"]
path = ~/Workspace/perso/.gitconfig
or或者
[includeIf "gitdir:~/Workspace/perso/**"]
path = ~/Workspace/perso/.gitconfig
or或者
[includeIf "gitdir:~/Workspace/perso/"]
path = ~/Workspace/perso/.gitconfig
IncludeIf
is indeed supported with Git 2.17.1 ( it was introduced in 2.13 ) IncludeIf
确实使用Git支持2.17.1(它在2.13中引入)
As commented, ~/.ssh/config
is only used for authentication, not authorship.正如所评论的,
~/.ssh/config
仅用于身份验证,而不是作者身份。
I would go to ~/Workspace/perso/my_perso_projec and do:我会去 ~/Workspace/perso/my_perso_projec 并执行以下操作:
git config --list --show-origin
That way, you know which file will set the user.email
.这样,您就知道哪个文件将设置
user.email
。
The last displayed overrides the others.最后显示的覆盖其他的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.