我想用用户名和密码运行 git 命令(比方说 push 命令)。但是密码最后有一个@ sing。所以它给了我这个错误。
Couldn't resolve host '@github.com'
我的示例 git 命令是这样的。
git push https://username:password@@github.com/username/test.git
我认为密码的结尾@符号是错误的原因。但无论如何,我想找到一种方法来一步运行此命令,而无需在第二步输入用户名和密码。
最佳答案
来自 RFC 1738:
"...Only alphanumerics [0-9a-zA-Z], the special characters "$-_.+!*'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."
因此您必须对 @ 字符进行 URL 编码:
git push https://username:password%40@github.com/username/test.git
但是,这极不安全。不仅 URL 在 HTTP 流量中清晰可读,而且它们被主机缓存,被记录器记录,并被代理和路由器以多种方式存储在到达目的地的路径上。 如果密码无法提供身份验证,为什么还需要密码?如果您不需要身份验证,请不要使用密码。
此外,浏览器不赞成在 URL 中提供密码,例如阅读 http://support2.microsoft.com/default.aspx?scid=kb;[LN];834489
有几种更安全的方法可以执行一步推送而无需输入密码,例如使用 SSH key 或 git config credential.helper
关于git - 提供带有密码的 git URL,包括 "@"符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32714399/