覆盖配置的用户进行单个git提交 [英] Override configured user for a single git commit

查看:108
本文介绍了覆盖配置的用户进行单个git提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的工作笔记本电脑上为 github.com 项目提交项目,该笔记本电脑已为公司配置git服务器。有没有办法提交指定不同的作者凭证,可能使用不同的配置文件或更多的命令行开关?



我试过使用

   -  author =我的名字< MyNameEmail@email.com> 

我收到了以下消息:

 提交者:未知< WorkEmail@workemail.net> 
您的姓名和电子邮件地址是基于您的用户名和主机名
自动配置的。请检查它们是否准确。
你可以通过显式地设置它来禁止这个消息:

git config --global user.nameYour Name
git config --global user.email you @ example。 com

做完这些之后,你可以修改用于这个提交的身份:

git commit --amend --reset-author

但它并没有更新我的用户名,因此无法提交到github.com项目。还有什么我可以尝试的,甚至有可能吗? 首先,作者不一定与提交者相同。 Git跟踪两者。



要设置该存储库使用的名称,您可以这样做:

  git config user.nameYour Name
git config user.email您的电子邮件

注意缺少 - global 选项。这将仅在此存储库中设置配置。您也可以通过命令行使用 -c 选项:

  git -cuser.name =您的名字-cuser.email =您的电子邮件提交... 

但我认为最好使用上面的配置选项。


I am trying to commit to a project on github.com from my work laptop, which is already configured for the company git server. Is there a way to commit specifying different author credentials, possible using a different configuration file or orther command line switches?

I've tried using

--author="My Name <MyNameEmail@email.com>" 

and I received the message:

 Committer: unknown <WorkEmail@workemail.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

but it still didn't update my username for committing to the github.com project. Is there anything else I can try and is it even possible?

解决方案

First, the author is not necessarily the same as the committer. Git tracks both.

To set what name to use for just this repository, you could do:

git config user.name "Your Name"
git config user.email "Your email"

Notice the absence of the --global option. This will set the configuration in this repository only. You can go this via the command line too, using the -c option:

git -c "user.name=Your Name" -c "user.email=Your email" commit ...

But I think it's better to just use the config options above.

这篇关于覆盖配置的用户进行单个git提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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