git 在git代理密码中转义@字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6172719/
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
Escape @ character in git proxy password
提问by Karthik
I have git proxy config as 'http.proxy=http://userId:pwd@123@ipaddress:port' but while cloning a remote project, I'm getting error as
我有 git 代理配置为 'http.proxy=http://userId: pwd@123@ipaddress:port' 但在克隆远程项目时,我收到错误
Cloning into git...
error: Couldn't resolve proxy '123@ipaddress' while accessing http://git.kernel.org/pub/scm/git/git.git/info/refs
fatal: HTTP request failed
How to escape the '@' character in password?
如何转义密码中的“@”字符?
Pls note: I cannot change the password.
请注意:我无法更改密码。
回答by John Weldon
I'd try using the URL Encoded value of the @ symbol (%40
) if you're passing the password in the proxy url:
%40
如果您在代理 url 中传递密码,我会尝试使用 @ 符号 ( )的 URL 编码值:
http.proxy=http://userId:pwd%40123@ipaddress:port
回答by VonC
Note (November 2013)
注(2013 年 11 月)
Encoding the url (especially any special character in a password) is the right solution.
The .netrc
mentioned below is only for remote repo url, not for the proxy used to resolve said remote repo url.
对 url 进行编码(尤其是密码中的任何特殊字符)是正确的解决方案。
在.netrc
下文提到的是仅用于远程回购网址,而不是用来解决代理表示远程回购网址。
For said encoding, see "Percent-encoding":
对于上述编码,请参阅“百分比编码”:
Percent-encoding, also known as URL encoding, is a mechanism for encoding information in a Uniform Resource Identifier(URI) under certain circumstances. Although it is known as URL encoding it is, in fact, used more generally within the main Uniform Resource Identifier(URI) set, which includes both Uniform Resource Locator(URL) and Uniform Resource Name(URN). As such, it is also used in the preparation of data of the application/x-www-form-urlencoded media type, as is often used in the submission of HTMLformdata in HTTPrequests.
Reserved characters after percent-encoding:
百分比编码,也称为 URL编码,是一种在特定情况下对统一资源标识符(URI) 中的信息进行编码的机制。尽管它被称为 URL 编码,但实际上,它在主要统一资源标识符(URI) 集中更普遍地使用,其中包括统一资源定位符(URL) 和统一资源名称(URN)。因此,它也用于准备 application/x-www-form-urlencoded媒体类型的数据,因为它经常用于在HTTP请求中提交HTML表单数据。
百分比编码后的保留字符:
! # $ & ' ( ) * + , / : ; = ? @ [ ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
Original answer (May 2011)
原始答案(2011 年 5 月)
Two comments:
两条评论:
having a password for a server accessed with http (not https) is... strange. The password isn't encrypted during communications between client and server;
you could setup a
.netrc
(or_netrc
for Windows) in your$HOME
, with the following content
为使用 http(不是 https)访问的服务器设置密码是......很奇怪。在客户端和服务器之间的通信过程中,密码没有加密;
你可以设置一个
.netrc
(或_netrc
在你的Windows)$HOME
,具有以下内容
machine ipaddress:port login userId password pwd@
The curl used by Git bbehind the scene would handle the encoding just fine, @
or no @
.
Git bbehind 使用的 curl 可以很好地处理编码,@
或者没有@
.
回答by conal_lab24
URL encode any unusual characters.
URL 编码任何异常字符。
@ character is %40
In my git config file, I have encoded 'just' the user name for instance:
在我的 git 配置文件中,我已经编码了“只是”用户名,例如:
https://myemail%[email protected]/api.git
回答by isnullxbh
For example, your password stored in environment variable GIT_PASSWORD
, username - GIT_USERNAME
, then:
例如,您的密码存储在环境变量中GIT_PASSWORD
,用户名 - GIT_USERNAME
,然后:
git clone http://${GIT_USERNAME}:$(echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %)@repository.git
Explanation of: echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %
说明: echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %
- Print password:
$GIT_REPOSITORY
<-hello
- Convert 'hello' to hex:
hello
<-x68x65x6Cx6Cx6F
- Change each 'x' to '%':
x68x65x6Cx6Cx6F
<-%68%65%6C%6C%6F
- 打印密码:
$GIT_REPOSITORY
<-hello
- 将“你好”转换为十六进制:
hello
<-x68x65x6Cx6Cx6F
- 将每个“x”更改为“%”:
x68x65x6Cx6Cx6F
<-%68%65%6C%6C%6F
回答by Ravi Parekh
You have to percent-encode| encodethe special characters. E.g. instead of this:
http://foo:B@[email protected]:80
you write this:
你这样写:
http://foo:B%[email protected]:80
So @
gets replaced with %40
.
所以@
被替换为%40
.