简体   繁体   English

将 git 设置为始终提示输入凭据

[英]Set git to always prompt for credentials

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.我希望 git 提交并推送以始终提示输入凭据。 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] .我尝试了一些在 SO 上找到的修复程序,包括git config --global --unset credential.helper以及编辑配置以在[core]下包含askpass = 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?这可能吗?

Edit: 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?这可能吗?

Regarding identity关于身份

See " How do I make git block commits if user email isn't set? "请参阅“如果未设置用户 email,我如何使 git 阻止提交?

git config --global user.useConfigOnly true

( With Git 2.21 , that works better with git stash too) 使用 Git 2.21 ,也可以更好地使用git stash

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.只要您不设置全局或本地用户名/电子邮件,这将使 Git 在每次提交时询问 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.强制您在每次提交时指定它们,如上所示。

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.这是一个可怕的想法:你确实想知道谁在每次提交时做了什么。

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.如果最近不得不开发一个git包装器来精确地强制用户,在他/她的第一个git命令上,到 select 是他/她的进程名称/git.xxx 文件,并将其存储在 /mp/git.xxx 文件中当前 bash 的 id。
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)这样,相同的包装器能够为在相同的 shell session 中完成的每个后续git命令设置正确的作者/电子邮件(由相同的用户)


Regarding password (authentication)关于密码(认证)

Make sure to use:确保使用:

An Git will ask for username/password on every push/pull. Git 将在每次推/拉时询问用户名/密码。
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.我确实确认,是否没有凭据缓存,并且HTTPS 是否用于远程存储库 URL(不是 SSH),每次拉/推/克隆操作都会出现提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM