将git设置为始终提示输入凭据 [英] Set git to always prompt for credentials
问题描述
由于某些特殊的硬件,我们有一台机器可以与一些开发人员共享.我想要git commits和push总是提示输入凭据.我已经尝试了一些关于SO的修复程序,包括 git config --global --unset credential.helper
,以及编辑配置以在下包含
.完成上述两项操作后,当我尝试提交时仍然可以得到此信息: askpass =
[核心]
Due to some specialized hardware, we have one machine that is shared with a few developers. I would like git commits and pushes to always prompt for credentials. I've tried a couple fixes found on SO including git config --global --unset credential.helper
as well as editing the config to include askpass =
under [core]
. After doing both of these, I still get this when I try to commit:
PS C:\Projects\Windows\projectname> git commit -m "testing shared credentials"
*** 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 'user@pcname.(none)')
我不想设置默认身份.我希望它每次从字面上询问用户名和密码.这可能吗?
I don't want to set a default identity. I want it to literally ask for a username and password every time. Is this possible?
我可以将默认标识设置为通用开发人员"或其他名称,但仍然提示输入凭据.
I would be okay with perhaps setting a default identity of "Generic Developer" or something but still prompting for credentials.
推荐答案
我希望它每次都要求输入用户名和密码.这可能吗?
I want it to literally ask for a username and password every time. Is this possible?
关于身份
git config --global user.useConfigOnly true
((使用Git 2.21 ,它在 git stash
上也能更好地工作)
(With Git 2.21, that works better with git stash
too)
只要您不设置全局或本地用户名/电子邮件,Git都会在每次提交时要求user.name/电子邮件.
That will make Git ask for user.name/email on every commit as long as you don't set a global or local user name/email.
然后,对于每个提交,您都可以在命令行上指定它(仅适用于该提交)
Then, for each commit, you can specify it on the command-line (that will apply for that commit only)
git -c user.name="My Name" -c user.email=my@email.com commit -m "my new commit"
一旦提交完成,任何新的提交都会再次询问您的用户名/电子邮件.
强制您在每次提交时指定它们,如上所示.
Once the commit done, any new commit would ask for your user name/email again.
Forcing you to specify them on each commit, as show above.
我可以设置默认身份为"Generic Developer"之类的东西
I would be okay with perhaps setting a default identity of "Generic Developer" or something
这是一个可怕的想法:您确实想知道谁在每次提交时都做了什么.
That is a dreadful idea: you do want to know who did what on each commit.
如果最近不得不精确地开发一个 git
包装器,以强制用户在其第一个 git
命令上选择其姓名/电子邮件,以及将其存储在/tmp/git.xxx文件中,其中xxx是当前bash的进程ID.
这样,相同的包装程序就可以为在同一shell会话中(大概由同一用户执行)的每个后续 git
命令设置适当的作者/电子邮件
If have had to develop recently a git
wrapper precisely to force a user, on his/her first git
command, to select his/her name/email, and store that in a /tmp/git.xxx file, with xxx being the process id of the current bash.
That way, the same wrapper is able to set the proper author/email for each subsequent git
commands done in the same shell session (by, presumably, the same user)
请务必使用:
- HTTPS URLS
- 没有凭据助手
一个Git会在每次推/拉时询问用户名/密码.
我确实确认,是否没有凭证缓存,并且是将HTTPS用于远程存储库URL(不是SSH),所以对于每个pull/push/clone操作都会出现提示.
An Git will ask for username/password on every push/pull.
I do confirm that, is there is no credential caching in place, and is HTTPS is used for the remote repository URL (not SSH), a prompt will take place for every pull/push/clone operation.
这篇关于将git设置为始终提示输入凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!