问题
IN SHORT
Is there a possibility to create a stash (using git stash create
) without the need to configure user.email
and user.name
? Something similar to the git commit --author
option?
SOME CONTEXT:
I have several build machines on which I have a build user. Each has acces to the central git repositories. However I haven't configured user.email
and user.name
for each of those users; since they never need to make commits.
In one of my scripts I use
git stash create
(which allows me to use git archive --format-gtz ... I'll spare you the detail; see my related question)
However this command fails:
*** 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: I have git 1.8.4
回答1:
With the git -c
flag configuration parameters can be passed on the command line:
git -c user.name=test -c user.email=test@test.com stash create
回答2:
With Git 2.21 (Q1 2019, 2+ years later), you won't have to configure user.email
and user.name
(git stash --author ?
).
A properly configured username/email is required under user.useConfigOnly
in order to create commits; now "git stash
" (even though it creates commit objects to represent stash entries) command is exempt from the requirement.
See commit 3bc2111 (18 Nov 2018) by Slavica Djukic (``).
Helped-by: Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 1328d29, 04 Jan 2019)
stash
: tolerate missing user identityThe "
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.
回答3:
If you just want to remove any local changes from the working copy and you are sure that there's nothing that needs to be saved for later, you could run the disturbingly dangerous command:
git checkout .
This question could be useful more broadly than just git stash create
(the issue applies to any use of git stash
). The question that I answered would probably be a dup of this question.
来源:https://stackoverflow.com/questions/36798310/git-create-stash-without-need-to-configure-user-email-and-user-name-git-stash