git 创建 stash 无需配置 user.email 和 user.name (git stash --author ?)

git create stash without need to configure user.email and user.name (git stash --author ?)

简而言之

是否可以创建存储(使用 git stash create而不需要 配置 user.emailuser.name?类似于 git commit --author 选项?

一些上下文:

我有几台构建机器,我有一个构建用户。每个人都可以访问中央 git 存储库。但是我还没有为每个用户配置 user.emailuser.name;因为他们永远不需要提交。

在我使用的一个脚本中

git stash create

(这让我可以使用 git archive --format-gtz ...我会省去你的细节;见我的 related question

但是这个命令失败了:

*** 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: empty ident name (for <macq@chmalap.macqel>) not allowed
Cannot save the current index state

PS: 我有 git 1.8.4

带git-c标志的配置参数可以在命令行传递:

git -c user.name=test -c user.email=test@test.com stash create

如果您只想从工作副本中删除任何本地更改,并且您确定没有任何内容需要为以后保存,您可以运行 令人不安的危险命令:

git checkout .

这个问题可能比 git stash create 更广泛有用(这个问题适用于 git stash 的任何使用)。我回答的问题可能是这个问题的重复。

有了 Git 2.21(2019 年第一季度,2 年多之后),您将不必配置 user.emailuser.name (git stash --author ?)。

user.useConfigOnly 下需要正确配置的 username/email 才能创建提交; 现在“git stash”(即使它创建提交对象来表示隐藏条目)命令不受要求

参见 commit 3bc2111 (18 Nov 2018) by Slavica Djukic (``)
帮助:Junio C Hamano (gitster).
(由 Junio C Hamano -- gitster -- in commit 1328d29 合并,2019 年 1 月 4 日)

stash: tolerate missing user identity

The "git stash" command insists on having a usable user identity to the same degree as the "git commit-tree" and "git commit" commands do, because it uses the same codepath that creates commit objects as these commands.

It is not strictly necessary to do so.

Check if we will barf before creating commit objects and then supply fake identity to please the machinery that creates commits.
Add test to document that stash executes correctly both with and without valid ident.

This is not that much of usability improvement, as the users who run "git stash" would eventually want to record their changes that are temporarily stored in the stashes in a more permanent history by committing, and they must do "git config user.{name,email}" at that point anyway, so arguably this change is only delaying a step that is necessary to work in the repository.