带有特殊字符的 TFS Git 命令行 [英] TFS Git command line with special characters
问题描述
我想用我的密码和用户名启动一个 git clone 命令,但我的密码包含特殊字符(例如:pass/word@123
):
I want to launch a git clone command with my password and username but my password contains special characters (e.g.: pass/word@123
) :
git clone https://username:pass/word@123@mysite.com/myrepo
该命令显然不起作用,因为它错误地解释了特殊字符.我尝试使用 百分比编码 和反斜杠,但它仍然无法正常工作.当我使用 password%40123
而不是 password@123
时,Git 说认证失败.我能做什么?
The command is obviously not working because it does wrongly interpret the special characters. I tried using percent encoding and backslash but it is still not working. Git says the authentication failed when I use password%40123
instead of password@123
. What can I do ?
注意:我使用的不是 github,而是 Microsoft TFS.
Note : I am not using github, but Microsoft TFS.
注意 2:当 git 询问时,我不能先输入 url,然后再输入密码(因为我尝试从 PHP/Symfony 运行命令(但直接从命令行使用百分比编码仍然不起作用))
Note 2 : I can not type the url first and the password after when git asks (because I try to run the command from PHP/Symfony (but percent encoding is still not working when using it directly from command line))
注意 3 : 当然我不能更改密码
Note 3 : Of course I cannot change the password
谢谢.
经过测试,它正在 GitHub 存储库(使用百分比编码)上工作,但不在 TFS 上.所以问题出在 TFS 上.
After testing, it is working on a GitHub repo (with percent encoding) but not on TFS. So the problem is coming from TFS.
推荐答案
正如你所说,它会将 @
后面的字符当作远程站点 url.
Just as you have said, it will treat characters after @
as the remote site url.
看看这个线程:如何在运行git clone git@remote.git"时提供用户名和密码?
在从客户操作系统自动执行 git 克隆时,使用 ssh 密钥 而不是密码更受欢迎.
It is more popular to use an ssh key instead of a password when automating a git clone from a guest OS.
如果您想使用带有特殊字符(如感叹号)的密码,则需要使用百分比编码,通常称为 URL 编码.
If you want to use password with special character, like an exclamation mark, you need to use percent encoding which is often called URL encoding.
! # $ & ' ( ) * + , / : ; = ? @ [ ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D
更多细节请参考这里的类似问题:在 git 代理密码中转义 @ 字符一个>
More details please refer similar question here: Escape @ character in git proxy password
这篇关于带有特殊字符的 TFS Git 命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!