如何在不配置的情况下使用git来应用补丁

6

我编写了一些使用git来应用一些补丁的指令。 这些指令旨在放入控制台中并一步完成操作。 就像这样:

git am bar.patch
git am foo.patch

但是现在 Git 要求用户提供姓名/电子邮件:
*** 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.

fatal: unable to auto-detect email address (got 'root@user-VirtualBox.(none)')
You need to set your committer info first

这似乎是不必要的,因为只有补丁作者出现在git日志中,而没有应用它们的人。是否有一种忽略配置的方法?
编辑:打字错误

1
所有提交都有作者和提交者,这是无法避免的。只配置一次用户名/电子邮件有什么问题吗? - Andrew C
问题在于人们复制并粘贴命令,却没有注意到 Git 无法应用补丁(因为 Git 没有配置)。 - mwarning
2个回答

2

请参考 "Git中作者和提交者的区别?"

当您应用补丁时,您是提交者。因此,Git需要知道“您”是谁。

关于git am,如果您希望与这些补丁相关的提交日期与补丁中记录的日期相同,我建议考虑使用--committer-date-is-author-date


补丁应用于本地存储库,最终被丢弃。我尝试使用git am --author "New Author Name email@address.com" foo.patch,但是git不接受这个命令。也许非git补丁是解决方案。 - mwarning

1

Git会检查GIT_COMMITTER_NAMEGIT_COMMITTER_EMAILEMAIL环境变量。以下是有效的:

EMAIL=root@localhost git am foo.patch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接