git 提交而不设置 user.email 和 user.name

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22058041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:48:33  来源:igfitidea点击:

Commit without setting user.email and user.name

git

提问by Paul Draper

I try to commit like this

我试着像这样提交

git commit --author='Paul Draper <[email protected]>' -m 'My commit message'

but I get

但我明白了

*** Please tell me who you are.

Run

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

I can set these, but I am on a shared box, and I would have to (want to) unset them afterwards.

我可以设置这些,但我在一个共享的盒子上,之后我必须(想要)取消它们。

git config user.name 'Paul Draper'
git config user.email '[email protected]'
git commit -m 'My commit message'
git config --unset user.name
git config --unset user.email

That's a lot of lines for one commit!

一次提交有很多行!

Is there shorter way?

有更短的方法吗?

回答by torek

(This occurred to me after suggesting the long version with the environment variables—git commit wants to set both an author and a committer, and --authoronly overrides the former.)

(这是在我建议使用环境变量的长版本之后发生的 - git commit 想要设置作者和提交者,并且--author只覆盖前者。)

All git commands take -carguments beforethe action verb to set temporary configuration data, so that's the perfect place for this:

所有 git 命令都在动作动词之前接受-c参数来设置临时配置数据,所以这是一个完美的地方:

git -c user.name='Paul Draper' -c user.email='[email protected]' commit -m '...'

So in this case -cis part of the gitcommand, not the commitsubcommand.

所以在这种情况下-cgit命令的一部分,而不是commit子命令。

回答by Kpym

You can edit the .git/configfile in your repo to add the following alias :

您可以编辑存储库中的.git/config文件以添加以下别名:

[alias]
  paulcommit = -c user.name='Paul Draper' -c user.email='[email protected]' commit

or you can do this by command line :

或者您可以通过命令行执行此操作:

git config alias.paulcommit "-c user.name='Paul Draper' -c user.email='[email protected]' commit"

And then you can do :

然后你可以这样做:

git paulcommit -m "..."

Remarks:

评论:

  • The idea is then to add also aliases like jeancommit, georgecommit, ... for the other users of this shared box.
  • You can add this alias to your global config by editing your personal .gitconfigor by adding --globaloption to the command line when adding the alias.
  • The alias paulcommitis not a short one, but it is verbose and you can in general type only git pau+tab.
  • 然后,我们的想法是为这个共享框的其他用户添加别名,如jeancommit, georgecommit, ... 。
  • 您可以通过编辑您的个人信息.gitconfig--global在添加别名时向命令行添加选项来将此别名添加到您的全局配置中。
  • 别名paulcommit不是一个简短的,但它是冗长的,您通常只能输入git pau+ tab