如何告诉 git 为给定项目使用正确的身份(姓名和电子邮件)? [英] How to tell git to use the correct identity (name and email) for a given project?

查看:20
本文介绍了如何告诉 git 为给定项目使用正确的身份(姓名和电子邮件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将个人笔记本电脑用于工作和个人项目,我想将我的工作电子邮件地址用于我的工作提交 (gitolite),而我的个人电子邮件地址用于其他工作 (github).

I use my personal laptop for both work and personal projects and I would like to use my work email address for my commits at work (gitolite) and my personal email address for the rest (github).

我阅读了以下解决方案,它们都是全局的或临时的:

I read about the following solutions which are all either global or temporary:

  • git config --global user.email "bob@example.com"
  • git config user.email "bob@example.com"
  • git commit --author "Bob "
  • 设置 GIT_AUTHOR_EMAILGIT_COMMITTER_EMAILEMAIL 环境变量之一
  • git config --global user.email "bob@example.com"
  • git config user.email "bob@example.com"
  • git commit --author "Bob <bob@example.com>"
  • setting one of the GIT_AUTHOR_EMAIL, GIT_COMMITTER_EMAIL or EMAIL environment variables

一种解决方案是手动运行一个 shell 函数,将我的环境设置为 workpersonal,但我很确定我经常忘记切换到正确的身份导致以错误的身份提交.

One solution is to run manually a shell function that sets my environment to work or personal, but I am pretty sure that I will often forget to switch to the correct identity resulting in committing under the wrong identity.

有没有办法将某个存储库、项目名称等绑定到一个身份(姓名、电子邮件)?人们做什么?

Is there a way of binding a certain repository, project name, etc. to an identity (name, email)? What do people do?

推荐答案

git config user.email "bob@example.com"

在存储库中执行此操作将在该存储库上设置配置,而不是全局设置.

Doing that one inside a repo will set the configuration on THAT repo, and not globally.

看来这就是您所追求的,除非我误读了您.

Seems like that's pretty much what you're after, unless I'm misreading you.

这篇关于如何告诉 git 为给定项目使用正确的身份(姓名和电子邮件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆