我将 Git 与两个不同的电子邮件/个人资料一起使用,结果是:
git config user.email >> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d5c1eaddc8d7fdd5d9d1d4f8d9dcdccaddcbcb96dbd7d5" rel="noreferrer noopener nofollow">[email protected]</a>
git config --global user.email >> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9783bd9f949f889399bf979b9396ba9b9e9e889f8989d4999597" rel="noreferrer noopener nofollow">[email protected]</a>
如果我使用 VS Code 并打开终端,我的提交将使用存储库电子邮件地址;这是有道理的,因为我正在有效地使用 Git(而不是 VSCode)。但是,如果我使用源代码管理 Git 侧边栏并键入提交消息,Ctrl+Enter
提交等,然后它使用全局电子邮件( <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="533e2a14363d36213a30163e323a3f13323737213620207d303c3e" rel="noreferrer noopener nofollow">[email protected]</a>
)提交,即使我正在具有不同设置的存储库中工作。
有没有办法告诉 VS Code 使用存储库的设置进行提交,而不是调用 --global
用于提交?
[编辑评论中的信息]
我想我应该提到我的 gitconfig 中有命令
[includeIf "gitdir:C:/Users/myname/privateRepoFolder"]
path = ~/gitconfig-private
在那个备用 gitconfig-private 中,我有
[user]
email = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="64091d3601140b2109050d0824050000160117174a070b09" rel="noreferrer noopener nofollow">[email protected]</a>
最佳答案
我终于有机会检查 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 = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2944507b4c59466c4448404569484d4d5b4c5a5a074a4644" rel="noreferrer noopener nofollow">[email protected]</a>
.
在 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 - 使用当前存储库的 user.email 在 VS Code 中进行提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55132043/