git clone – URL中的空格问题

huangapple go评论55阅读模式
英文:

git clone - Issue with whitspace within URL

问题

我在使用带有空格名称的存储库时遇到问题。

例如,在AzureDevOps中,我的项目名称是:"TestProject - Test",克隆我的git存储库的URL如下:

git clone --mirror https://xxxPAT@dev.azure.com/organizationname/"TestProject - Test"/_git/"TestProject - Test"

然而,如果我保留URL不变,git会抛出错误,说“找不到存储库”,因为它只识别URL到第一个空格为止。

如果我将存储库名称放在双引号或单引号中,我会得到“URL使用不良/非法格式或缺少URL”的错误。

我还尝试过使用Google建议的%20来转义空格:

.../organizationname/TestProject%20-%20Test/_git/TestProject%20-%20Test

但是git会将URL解析为/organizationname/TestProject0-0Test/_git/TestProject0-0Test,这使它无法找到项目,因为它不存在零字符而不是空格。

有没有人有解决这个问题的想法?提前谢谢。

英文:

I am having issues using git clone with repositories that have whitespace in their names.

For example, my project name in AzureDevOps is: "TestProject - Test" and the URL to clone my git repo is:

git clone --mirror https://xxxPAT@dev.azure.com/organizationname/"TestProject - Test"/_git/"TestProject - Test"

However, if I leave the URL like this, git throws an error saying "repository not found" as it only recognizes the URL until the first whitespace.

If I put the repository name in double or single quotation marks, I get "URL using bad/illegal format or missing URL" error.

I have also tried to escape the whitespace with %20, as suggested by Google:

.../organizationname/TestProject%20-%20Test/_git/TestProject%20-%20Test

But git resolves the URL as /organizationname/TestProject0-0Test/_git/TestProject0-0Test, making it unable to find the project as it doesn't exist with a zero character instead of the whitespace.

Does anyone have an idea how to solve this issue? Thank you in advance.

答案1

得分: 1

"%2" 被替换为 "0" 可能是某种与操作系统有关的 shell 参数替换,具体取决于您使用的操作系统。没有进一步的信息,我建议尝试使用 "%%20" 来转义百分号符号。

英文:

The %2 being replaced by 0 might be some sort of shell argument replacing, depending on what operating system you are using. Without further information I would suggest trying %%20 to escape the %-sign.

huangapple
  • 本文由 发表于 2023年6月16日 16:01:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76488128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定