简体   繁体   English

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

[英]Any way to change Author e-mail in VS code for git commits?

Vars summary: I am using corporate machine (corp.company.com) with VS Code installed on it (win10), using VSTS (Azure DevOps) with hosted there git which belongs to another organization (another.com). Vars摘要:我正在使用安装了VS Code的公司机器(corp.company.com)(win10),使用VSTS(Azure DevOps)并托管在git属于另一个组织(another.com)。 Global and local Gitconfig is configured to use alexsun@another.com as user.email since VSTS accepts commits only from @another.com (policy).全局和本地 Gitconfig 配置为使用 alexsun@another.com 作为 user.email,因为 VSTS 仅接受来自 @another.com 的提交(策略)

The problem is that when I try to commit and push to VSTS from VScode, author of commits becomes myusername@corp.company.com and push is failing due to policy described above.问题是,当我尝试从 VScode 提交和推送到 VSTS 时,提交的作者变为 myusername@corp.company.com 并且由于上述策略而推送失败。 When in VScode executing commit and push via Terminal (WSL), it is all working fine and commits are saved as by alexsun@another.com.在 VScode 中通过终端(WSL)执行提交和推送时,一切正常,提交保存为 alexsun@another.com。

I rebuilt local repo multiple times (by cloning remote repo), disabled credentials helper.我多次重建本地仓库(通过克隆远程仓库),禁用凭据助手。 Still when committing and pushing with VScode author becomes myusername@corp.company.com, when committing via cli then all is good - alexsun@another.com.仍然当使用 VScode 提交和推送时,作者变为 myusername@corp.company.com,当通过 cli 提交时,一切都很好 - alexsun@another.com。

Btw myusername@corp.company.com is the same as username for logging into the Win machine.顺便说一句 myusername@corp.company.com 与登录 Win 机器的用户名相同。 I checked Windows Credentials Manager and for git it is also alexsun@another.com.我检查了 Windows 凭据管理器,对于 git,它也是 alexsun@another.com。 myusername@corp.company.com is only set for O365 creds there. myusername@corp.company.com 仅设置为那里的 O365 凭据。

Anyone?任何人?

We could check the commit Author info via the git cmd.我们可以通过 git cmd 检查提交作者信息。

git config user.name // Check your user name
git config user.email // Check the associated email

You could run it cmd to check the commit owner, in your vs code, it should be myusername@corp.company.com , we need to change the email address to alexsun@another.com via git config user.email "alexsun@another.com" , you need to change it, run the cmd to check the email address and ensure the result is @another.com , then it will work. You could run it cmd to check the commit owner, in your vs code, it should be myusername@corp.company.com , we need to change the email address to alexsun@another.com via git config user.email "alexsun@another.com" ,你需要更改它,运行 cmd 检查 email 地址并确保结果是@another.com ,然后它会工作。

git cmd git cmd

git config user.name "newemail"
git config user.email "newemail@example.com"

Result:结果:

在此处输入图像描述

update1更新1

git config --global user.name "newemail"
git config --global user.email "newemail@example.com"

The above will be a global change meaning that it'll change it for all git projects以上将是全局更改,这意味着它将针对所有 git 项目进行更改

Update2更新2

VS code push the commit via git, If we update the git configuration, and it will change the VS code configuration. VS 代码通过 git 推送提交,如果我们更新 git 配置,它会改变 VS 代码配置。 This is my test steps, you could check it.这是我的测试步骤,你可以检查一下。

在此处输入图像描述

Change the commit Author info via the git cmd and result通过 git cmd 和结果更改提交作者信息

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM