git-svn 克隆失败 "fatal: Not a valid object name"。

18

执行git svn clone -s https://svn.example.com/repo/命令时,我收到了以下输出:

r3073 = a6132f3a937b632015e66d694250da9f606b8333 (refs/remotes/trunk)
Found possible branch point: https://svn.example.com/repo/trunk => https://svn.example.com/repo/branches/v1.3, 3073
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
    real path: repo/trunk
Continuing ahead with repo/trunk
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
    real path: repo/trunk
Continuing ahead with repo/trunk
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
    real path: repo/trunk
Continuing ahead with repo/trunk
W: Refspec glob conflict (ref: refs/remotes/trunk):
expected path: repo/branches/trunk
    real path: repo/trunk
Continuing ahead with repo/trunk
fatal: Not a valid object name refs/remotes/tags/Sync Controllers
cat-file commit refs/remotes/tags/Sync Controllers: command returned error: 128

运行git branch -a命令会输出:

remotes/tags/Sync%20Controllers
remotes/tags/v1.1
remotes/trunk
remotes/v1.2
我认为问题在于 "remotes/tags/Sync Controllers" 与 "remotes/tags/Sync%20Controllers" 不相同。

请参阅: https://bugs.launchpad.net/ubuntu/+source/git/+bug/786942 - kenorb
相关链接:https://dev59.com/k1vUa4cB1Zd3GeqPwLiD 那里有一个补丁可用。 - kenorb
5个回答

32

SVN中的标签中有一个空格,但是git中的标签将这个空格转换为%20(URL编码)。要解决这个问题,只需手动添加一个与原名称完全相同的新标签:

cd .git/refs/remotes/tags/
mv Sync%20Controllers Sync\ Controllers

然后再次运行git svn clone命令。

(通常你可以通过git tag OLDTAG NEWTAG来完成这个操作,但是git不允许我定义一个带有空格的标签。标签文件只是包含相关提交哈希的文本文件。)


4
我尝试了那个解决方案,但是我遇到了以下错误: “致命错误:引用格式无效:'refs/remotes/tags/WITH SPACE'”。该如何解决? - D.R.
你好,你知道在分支情况下如何解决这个问题吗?https://dev59.com/xZDea4cB1Zd3GeqPfK8A - Idemax
2
可能是相同的,但是改为 cd .git/refs/heads/ 或者 cd .git/logs/refs/heads/ - Benjie
3
更新.git/packged-refs文件并将所有的%20替换为空格,这对我有用... git 2.18.0 - MSillence
@MSillence 救命稻草。今天在运行 git svn 克隆了 24 小时后出现网络超时故障,修改 .git/packaged-refs 并删除 %20 可以让它继续从中断的地方继续。 - James Manes
显示剩余4条评论

5

您可以使用git-svn的服务器端替代方案SubGit,以避免许多git-svn翻译问题。

我是SubGit的开发人员,可以说我们花了很多时间来解决像上面那样的字符翻译问题; 在这种特殊情况下,标签将被翻译为refs/tags/Sync+Controllers标签。

请注意,git-svn将翻译Subversion标记为分支而不是标记。


我需要在服务器上安装SubGit吗?如果我没有svn仓库的管理员访问权限怎么办? - kenorb
使用SubGit 2.0,您无需对存储库进行管理员访问。您需要启用pre-revprop-change钩子以获取完整的作者映射功能,但很有可能已经启用。请查看http://subgit.com/eap/获取更多详细信息。 - Alexander Kitaev

5

今天我遇到了这个问题,考虑到这个分支包含一个步伐,不是很重要,所以我继续执行。

git branch -r -d partialPayment%202.4

重新运行 git svn fetch 命令,它将跳过当前分支并继续抓取下一个分支。

1
我正在使用git 1.29.2,并遇到了这个问题。此外,它在Windows Server 2016上运行,而git是在cygwin下运行的。
检查/GitMigration/.git/svn/refs/remotes/origin,该文件夹存在,但空格不是%20,因此无需更改任何内容。
然而,在packed-refs中,导致问题的标签未出现,没有名称和哈希值。
问题应该与其他产生错误的东西有关,而不仅仅是这个问题。
查看./.git/config,发现以下行的一系列重复:
branches = server/branches/*:refs/remotes/origin/*
tags = server/tags/*:refs/remotes/origin/tags/*

每次我运行git-svn clone命令时,都会产生这些内容。因此,我将其从配置文件中删除,保存并再次运行,但这次使用git svn fetch,以防止再次获取重复的行,问题解决了。

0

我相信空格问题已经在 Git >= 1.8.0 中得到解决(请参见:#786942)。

所以你应该升级它。

我已经测试过了,它似乎在最近的 Git 版本中可以正常工作。

请查看 GitHub 主页:https://github.com/git/git


4
我正在使用1.8.5.2版本,并遇到了这个问题。 - krinker
你认为这是否与分支/标签名称中的空格或特殊字符有关? - kenorb
我也遇到了这个问题,使用的是git = 1.8.3.1,svn = 1.7.14和svn2git = 2.3.2。与SVN分支名称中的空格有关。 - jplandrain
3
我使用的是Git版本2.23.0,最近遇到了这个问题。 - Asad Ali

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接