Git Windows 禁用密码提示 UI 但从 shell 获取密码提示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34396390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:39:29  来源:igfitidea点击:

Git Windows Disable password prompt UI but get password prompt from shell

gitgit-bash

提问by Yogesh_D

In git bash for windows, the username and/or password is asked in a separate UI popup prompt like below.

在 Windows 的 git bash 中,用户名和/或密码在一个单独的 UI 弹出提示中被询问,如下所示。

Username Prompt

用户名提示

On Hitting Cancel you get the below shell based prompt, where the same username can be input.

在点击取消时,您会看到以下基于 shell 的提示,其中可以输入相同的用户名。

Shell based username prompt

基于 Shell 的用户名提示

Is there a way I can disable these prompts? I still do want to enter my username and password however instead of the UI based prompt, i want to enter it through the shell based prompt.

有什么办法可以禁用这些提示吗?我仍然想输入我的用户名和密码,但不是基于 UI 的提示,我想通过基于 shell 的提示输入它。

Using suggestions from this does not help. How to undo git config --system core.askpass git-gui--askpass

使用这方面的建议无济于事。如何撤消 git config --system core.askpass git-gui--askpass

回答by hinneLinks

Try to blank the variable core.askPassglobally (in your config-file)

尝试core.askPass全局清空变量(在您的配置文件中)

$ git config --global core.askPass ""

or use the -cswitch to override it just for one command

或使用-c开关仅针对一个命令覆盖它

$ git -c core.askPass="" clone <https_url>

see: https://git-scm.com/docs/gitcredentials

请参阅:https: //git-scm.com/docs/gitcredentials

Note: un-setting the core.askPassby using git config --global --unset core.askPassdoesn't help. It needs to be set to an empty string like above.

注意:core.askPass通过使用取消设置git config --global --unset core.askPass没有帮助。它需要像上面一样设置为空字符串。

回答by CodeWizard

Use ssh instead of http/https.

使用 ssh 而不是 http/https。

You will need to set ssh keys on your local machine, upload them to your git server and replace the url form http://to git://and you will not need to use passwords anymore.

您需要在本地机器上设置 ssh 密钥,将它们上传到您的 git 服务器并将 url 表单替换http://git://,您将不再需要使用密码。

If you cant use ssh add this to your config:

如果您不能使用 ssh,请将其添加到您的配置中:

[credential "https://example.com"]
    username = me

documents are here.

文件在这里

回答by Jason Tien

You may try the configuration below:

您可以尝试以下配置:

git config --global --unset credential.helper

and

git config --system --unset credential.helper

This helped me while I am using PortableGit 64-bit 2.12.1.1 on Windows 7.

当我在 Windows 7 上使用 PortableGit 64 位 2.12.1.1 时,这对我有所帮助。

回答by Raghavendran Srinivasan

In my case I've been using git 1.9.5 for 3 years. And recently I tried to install latest version 2.15.0. In the latest git bash when I do git pull it was asking me to enter password whereas in old git version(1.9.5) it won't ask anything like that.

就我而言,我已经使用 git 1.9.5 3 年了。最近我尝试安装最新版本 2.15.0。在最新的 git bash 中,当我执行 git pull 时,它要求我输入密码,而在旧的 git 版本(1.9.5)中,它不会问任何类似的问题。

I did search in google. Finally my friend helped me to resolve that. It is because I've configured dsa key instead of rsa key. As per my understanding dsa is old key format and rsa is new key format.

我确实在谷歌搜索过。最后我的朋友帮我解决了这个问题。这是因为我配置了 dsa 密钥而不是 rsa 密钥。根据我的理解,dsa 是旧的密钥格式,而 rsa 是新的密钥格式。

To use the latest git bash with old dsa key I did the below thing, create a file named "config"(It is the full name) inside your .ssh folder. In that file give the below note,

要使用带有旧 dsa 密钥的最新 git bash,我做了以下事情,在 .ssh 文件夹中创建一个名为“config”(它是全名)的文件。在该文件中给出以下注释,

PubkeyAcceptedKeyTypes=+ssh-dss

PubkeyAcceptedKeyTypes=+ssh-dss

And save it.

并保存它。

Now open the latest git bash. And do git pull. It won't ask any password and just pull the commits.

现在打开最新的 git bash。并做 git pull。它不会询问任何密码,只会拉提交。

回答by Alex Palmer

Unset SSH_ASKPASS.

取消设置SSH_ASKPASS

unset SSH_ASKPASS

To do this automatically each time you open git bash, you can add the above line to the end of your .bashrc.

要在每次打开 git bash 时自动执行此操作,您可以将上述行添加到 .gitignore 文件的末尾.bashrc

Investigation

调查

The gitcredentials docslinked in other answers list a number of places git will check to determine how to ask for a password. I investigated each in turn:

其他答案中链接的 gitcredentials 文档列出了 git 将检查以确定如何要求输入密码的许多地方。我依次调查了每一个:

env | grep GIT
git config --get core.askPass
env | grep SSH

The last command told me SSH_ASKPASSexisted:

最后一个命令告诉我SSH_ASKPASS存在:

SSH_ASKPASS=/mingw64/libexec/git-core/git-gui--askpass`.

This is not part of my dotfiles, and so seems to come from the default Windows git distribution from http://git-scm.com.

这不是我的点文件的一部分,因此似乎来自http://git-scm.com的默认 Windows git 发行版。