【问题标题】:Managing multiple git commit email addresses管理多个 git commit 电子邮件地址
【发布时间】:2021-03-16 08:31:33
【问题描述】:

我使用我的个人笔记本电脑工作(他们对此很好),但我注意到我所有的工作提交都使用我的个人电子邮件地址。我不想在我的机器上为 git 全局默认使用我的工作电子邮件地址,有没有一种方法可以让我在提交时将我的个人电子邮件地址用于某些存储库,并将我的工作电子邮件地址用于其他存储库?

我不介意重写现有提交的历史记录,只是继续前进。

【问题讨论】:

  • 您可以在本地为该副本设置电子邮件。只需像在 repo 文件夹中一样设置它,省略 --global 标志。 git config user.email your.work.email@domain.com

标签: git gitlab commit git-commit


【解决方案1】:

@RomainValeri 提供的另一种解决方案是使用“条件包含”git 功能(我觉得更方便)

您可以将所有个人存储库放在特定文件夹中(此处为~/personal/)并设置配置,以便当您使用 git 时,它将对该文件夹内的所有存储库使用特定配置。

这样,您在克隆或创建新存储库时就不会忘记设置个人设置。

你可以这样做:

~/.gitconfig

[user]
    name = John Doe
    email = john.doe@work-account.com

[includeIf "gitdir:~/personal/"]
    path = ~/personal/.gitconfig

在包含您的个人信息~/personal/.gitconfig的新配置文件中:

[user]
    email = john.doe@personal-account.com

编辑:再次阅读你的问题,因为那是你的个人电脑,也许你想做相反的事情,所以你只需要切换两封电子邮件......

【讨论】:

  • 确实很有趣 :-) 值得考虑。
【解决方案2】:

是的,您可以利用 --local 设置来精确管理每个 repo 应使用的电子邮件。

# to set your work email only for the current repo
git config --local user.email '<your work email>'

# to set an email globally, as a fallthrough if a repo doesn't have a local setting for user.email
git config --global user.email '<your personal email>'

【讨论】:

  • 仅供参考 (/cc @SimonBarker) ,我提出了使用“条件包含”找到更方便的解决方案
猜你喜欢
  • 2018-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-29
  • 1970-01-01
  • 2015-01-23
  • 2017-07-23
  • 2016-10-14
相关资源
最近更新 更多