【问题标题】:Any way to change Author e-mail in VS code for git commits?有什么方法可以在 VS 代码中更改作者电子邮件以进行 git 提交?
【发布时间】:2020-12-07 23:15:23
【问题描述】:

Vars 摘要:我正在使用安装了 VS Code 的公司机器 (corp.company.com) (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 凭据管理器,对于 git,它也是 alexsun@another.com。 myusername@corp.company.com 仅设置为那里的 O365 凭据。

有人吗?

【问题讨论】:

  • 只是检查一下这个问题现在是否仍然阻止您?这个问题有更新吗?
  • 谢谢,我觉得还没有完全解决。有时它与 VSCode 一起使用,但并非总是如此,并且总是与 git cli 一起使用。我在雾化情况下使用 cli。感谢您的帮助

标签: git visual-studio-code azure-devops


【解决方案1】:

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

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

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

git 命令

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

结果:

更新1

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

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

更新2

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

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

【讨论】:

  • 请注意您有本地和全局配置
  • 请仔细阅读问题描述 - 我描述了我将全局和本地 gitconfig 更改为使用 alexsun@another.com 并通过 cli 在同一个 repo 上工作正常,但是使用内置 -在 VScode 的“提交”功能/按钮中,然后它将 myusername@corp.company.com 作为作者。执行git config --list --show-origin 时,它会将alexsun@another.com(正确的一个)显示为user.email。我需要帮助来配置 VScode,而不是 git。谢谢!
  • 嗨@AlexSun.dr,VS代码通过git推送提交,我们只需要更改git的配置,这将改变VS代码的配置,我已经用详细步骤更新了我的答案,您可以查看它,如果您有任何疑问,请随时在这里分享。
  • 嗨@AlexSun.dr,这个问题怎么样?下面的答案是否解决了您的问题?如果没有,请告诉我有关此问题的最新信息吗?
猜你喜欢
  • 2016-04-23
  • 1970-01-01
  • 2018-11-21
  • 2012-08-29
  • 2018-05-05
  • 2018-04-27
相关资源
最近更新 更多