使用当前 repo 的 user.email 在 VS Code 中提交
Use current repo's user.email for commits in VS Code
我将 Git 与两个不同的电子邮件/配置文件一起使用,导致:
git config user.email >> myRepoEmail@address.com
git config --global user.email >> myGenericEmail@address.com
如果我使用 VS Code 并打开一个终端,我的提交使用 repo 电子邮件地址;这是有道理的,因为我有效地使用了 Git(而不是 VSCode)。但是,如果我使用源代码管理 Git 侧边栏并键入提交消息,Ctrl+Enter
提交等,那么它会使用全局电子邮件 (myGenericEmail@address.com
) 提交,即使我是在具有不同设置的回购中工作。
有没有办法告诉 VS Code 使用存储库的设置进行提交,而不是调用 --global
进行提交?
[编辑来自评论的信息]
我想我应该提到我的 gitconfig 命令中有
[includeIf "gitdir:C:/Users/myname/privateRepoFolder"]
path = ~/gitconfig-private
在备用 gitconfig-private 中,我有
[user]
email = myRepoEmail@address.com
With Git 2.8 or more,其实我会推荐:
git config --global user.useConfigOnly true
然后启动 VSCode。
这样,如果出于任何原因,VSCode 找不到您在任何本地仓库中配置的 user.name
/user.email
,则 VSCode 无法默认为通用电子邮件:它会 有问你在那个回购中是谁。
我终于有机会查看 Windows。
来自您的评论:
I suppose I should mention I have in my gitconfig the command
[includeIf "gitdir:C:/Users/myname/privateRepoFolder"]
path =
~/gitconfig-private
, and in that alternate gitconfig-private, I have
[user] email = myRepoEmail@address.com
.
关于Windows,includeIf
conditional include对路径有点讲究
首先,确保以/
结束路径以指定目录,如他们的示例:
; include for all repositories inside /path/to/group
[includeIf "gitdir:/path/to/group/"]
path = /path/to/foo.inc
所以你应该使用:
[includeIf "gitdir:C:/Users/myname/privateRepoFolder/"]
path = ~/gitconfig-private
我发现它也可以通过以 .git 文件结尾的路径来工作(更明确地说)。
[includeIf "gitdir:C:/Users/myname/privateRepoFolder/.git"]
path = ~/gitconfig-private
其次,对于VSCode,只有使用不区分大小写的路径匹配才有效(gitdir/i
):
[includeIf "gitdir/i:C:/Users/myname/privateRepoFolder/"]
path = ~/gitconfig-private
这种不区分大小写的行为是 VSCode 的已知行为。
查看报告的问题 Git integration does not correctly support includeIf
directive:
I tried to commit from VSCode, which failed to pick up the includeIf
config. Then I ran the wrapper from the command line, and it did pick
up the includeIf. I then checked the log:
In VSCode:
config --get-all user.name in c:\Users\zhuowei\Documents\repos\includeIf
Outside:
config --get-all user.name in C:\Users\zhuowei\Documents\repos\includeIf
Note the difference in the case letter.
我将 Git 与两个不同的电子邮件/配置文件一起使用,导致:
git config user.email >> myRepoEmail@address.com
git config --global user.email >> myGenericEmail@address.com
如果我使用 VS Code 并打开一个终端,我的提交使用 repo 电子邮件地址;这是有道理的,因为我有效地使用了 Git(而不是 VSCode)。但是,如果我使用源代码管理 Git 侧边栏并键入提交消息,Ctrl+Enter
提交等,那么它会使用全局电子邮件 (myGenericEmail@address.com
) 提交,即使我是在具有不同设置的回购中工作。
有没有办法告诉 VS Code 使用存储库的设置进行提交,而不是调用 --global
进行提交?
[编辑来自评论的信息]
我想我应该提到我的 gitconfig 命令中有
[includeIf "gitdir:C:/Users/myname/privateRepoFolder"]
path = ~/gitconfig-private
在备用 gitconfig-private 中,我有
[user]
email = myRepoEmail@address.com
With Git 2.8 or more,其实我会推荐:
git config --global user.useConfigOnly true
然后启动 VSCode。
这样,如果出于任何原因,VSCode 找不到您在任何本地仓库中配置的 user.name
/user.email
,则 VSCode 无法默认为通用电子邮件:它会 有问你在那个回购中是谁。
我终于有机会查看 Windows。
来自您的评论:
I suppose I should mention I have in my gitconfig the command
[includeIf "gitdir:C:/Users/myname/privateRepoFolder"]
path =
~/gitconfig-private
, and in that alternate gitconfig-private, I have[user] email = myRepoEmail@address.com
.
关于Windows,includeIf
conditional include对路径有点讲究
首先,确保以/
结束路径以指定目录,如他们的示例:
; include for all repositories inside /path/to/group
[includeIf "gitdir:/path/to/group/"]
path = /path/to/foo.inc
所以你应该使用:
[includeIf "gitdir:C:/Users/myname/privateRepoFolder/"]
path = ~/gitconfig-private
我发现它也可以通过以 .git 文件结尾的路径来工作(更明确地说)。
[includeIf "gitdir:C:/Users/myname/privateRepoFolder/.git"]
path = ~/gitconfig-private
其次,对于VSCode,只有使用不区分大小写的路径匹配才有效(gitdir/i
):
[includeIf "gitdir/i:C:/Users/myname/privateRepoFolder/"]
path = ~/gitconfig-private
这种不区分大小写的行为是 VSCode 的已知行为。
查看报告的问题 Git integration does not correctly support includeIf
directive:
I tried to commit from VSCode, which failed to pick up the includeIf config. Then I ran the wrapper from the command line, and it did pick up the includeIf. I then checked the log:
In VSCode:
config --get-all user.name in c:\Users\zhuowei\Documents\repos\includeIf
Outside:
config --get-all user.name in C:\Users\zhuowei\Documents\repos\includeIf
Note the difference in the case letter.