无需设置user.email和user.name即可提交

Pau*_*per 69 git

我试着像这样做

git commit --author='Paul Draper <my@email.org>' -m 'My commit message'
Run Code Online (Sandbox Code Playgroud)

但我明白了

*** Please tell me who you are.

Run

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

to set your account's default identity.
Omit --global to set the identity only in this repository.
Run Code Online (Sandbox Code Playgroud)

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

git config user.name 'Paul Draper'
git config user.email 'my@email.org'
git commit -m 'My commit message'
git config --unset user.name
git config --unset user.email
Run Code Online (Sandbox Code Playgroud)

这是一个提交的很多行!

有更短的路吗?

tor*_*rek 102

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

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

git -c user.name='Paul Draper' -c user.email='my@email.org' commit -m '...'
Run Code Online (Sandbox Code Playgroud)

  • @msb:Git在1.7.2版中学习了git -c([错过了这么多:-:](https://www.youtube.com/watch?v=oPwrodxghrw))。 (3认同)
  • @DaniloPianini:现在 Git 维护者的邮件列表上有一些关于与此相关的事情和/或与“git merge”一起使用的错误讨论。最近的一些变化似乎破坏了一些东西。他们多久能修好,我不确定。但是,请注意,您应该使用“git -c ... commit -m ...”,而不是“git commit -c ... -m ...”。换句话说,这里的“-c”选项是“git”,而不是“git commit”。 (2认同)

Kpy*_*pym 13

您可以.git/config在repo中编辑文件以添加以下别名:

[alias]
  paulcommit = -c user.name='Paul Draper' -c user.email='my@email.org' commit
Run Code Online (Sandbox Code Playgroud)

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

git config alias.paulcommit "-c user.name='Paul Draper' -c user.email='my@email.org' commit"
Run Code Online (Sandbox Code Playgroud)

然后你可以这样做:

git paulcommit -m "..."
Run Code Online (Sandbox Code Playgroud)

备注:

  • 我们的想法是那么还添加别名一样jeancommit,georgecommit...这个共享盒的其他用户.
  • 您可以通过编辑个人.gitconfig--global在添加别名时向命令行添加选项,将此别名添加到全局配置中.
  • 别名paulcommit不是一个短的,但它是冗长的,你通常只能键入git pau+ tab.