有什么方法可以更改 VS code 中 git 提交的作者电子邮件吗?

Ale*_*.dr 1 git visual-studio-code azure-devops

变量摘要:我正在使用企业计算机(corp.company.com),上面安装了 VS Code(win10),使用 VSTS(Azure DevOps)并托管了属于另一个组织(another.com)的 git。全局和本地 Gitconfig 配置为使用 alexsun@another.com 作为 user.email,因为 VSTS 仅接受来自 @another.com 的提交(策略)。

问题是,当我尝试从 VScode 提交并推送到 VSTS 时,提交的作者变为 myusername@corp.company.com,并且由于上述策略,推送失败。当在 VScode 中通过终端(WSL) 执行提交和推送时,一切正常,并且提交保存为 alexsun@another.com。

我多次重建本地存储库(通过克隆远程存储库),禁用凭据帮助程序。尽管如此,当使用 VScode 提交和推送时,作者变为 myusername@corp.company.com,当通过 cli 提交时,一切都很好 - alexsun@another.com。

顺便说一句,myusername@corp.company.com 与登录 Win 计算机的用户名相同。我检查了 Windows Credentials Manager,对于 git,它也是 alexsun@another.com。myusername@corp.company.com 仅针对 O365 信用设置。

任何人?

Vit*_*Liu 6

我们可以通过 git cmd 检查提交作者信息。

git config user.name // Check your user name
git config user.email // Check the associated email
Run Code Online (Sandbox Code Playgroud)

你可以运行cmd来检查提交所有者,在你的vs代码中,应该是myusername@corp.company.com,我们需要将电子邮件地址更改为alexsun@another.comvia git config user.email "alexsun@another.com",你需要更改它,运行cmd来检查电子邮件地址并确保结果是@another.com,然后它就会起作用。

git 命令

git config user.name "newemail"
git config user.email "newemail@example.com"
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

更新1

git config --global user.name "newemail"
git config --global user.email "newemail@example.com"
Run Code Online (Sandbox Code Playgroud)

以上将是一个全局更改,这意味着它将针对所有 git 项目进行更改

更新2

VS code通过git推送提交,如果我们更新git配置,它会改变VS code配置。这是我的测试步骤,你可以看看。

在此输入图像描述

通过 git cmd 和结果更改提交作者信息

在此输入图像描述