在我的~/.gitconfig中,我在[user]下列出了我的个人电子邮件地址,因为这就是我想要用于Github repos的地址。
但是,我最近也开始在工作中使用git。我的公司的git repo允许我提交,但当它发出新变更集的公告时,它会说它们来自匿名,因为它无法识别我.gitconfig中的电子邮件地址-至少,这是我的理论。
是否可以在.gitconfig中指定多个[user]定义?或者,是否有其他方法可以覆盖某个目录的默认.gitconfig?在我的例子中,我签出了~/worksrc/中的所有工作代码--有没有办法只为该目录(及其子目录)指定一个.gitconfig?
发布于 2010-11-19 06:56:07
您可以将单个存储库配置为使用覆盖全局配置的特定用户/电子邮件地址。从repo的根目录中,运行
git config user.name "Your Name Here"
git config user.email your@email.com而默认用户/电子邮件是在~/.gitconfig中配置的
git config --global user.name "Your Name Here"
git config --global user.email your@email.com发布于 2017-04-27 17:40:16
从git 2.13开始,可以使用新引入的Conditional includes来解决这个问题。
举个例子:
全局配置~/.gitconfig
[user]
name = John Doe
email = john@doe.tld
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig工作特定配置~/ Work /.gitconfig
[user]
email = john.doe@company.tld请记住,在顶部,[includeIf...]应该遵循默认的[user]。
发布于 2013-04-12 19:03:21
或者,您可以在本地.git/config文件中添加以下信息
[user]
name = Your Name
email = your.email@gmail.comhttps://stackoverflow.com/questions/4220416
复制相似问题