【发布时间】:2013-04-11 03:42:04
【问题描述】:
我已按照this tutorial 将一个 SVN 存储库转换为 Git。现在似乎无法像this answer 中建议的那样提取子存储库。
请原谅这篇长文,但大部分文字都是格式精美的 git 输出。
操作系统:Windows 8 命令行:MinGW Git版本:1.8.1.msysgit.1
除非您有一个干净的暂存区并且没有修改过的文件,否则提取子存储库的过程似乎不起作用。
git status 告诉我我有一个修改过的文件,即使这是一个全新的 SVN 导入。好吧,让我们试着摆脱它。
尝试恢复文件。
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
user$ git checkout -- "folder with space/folder/toolbar.png"
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
这不起作用,但我不在乎我是否提交它,所以我接下来会尝试。
user$ git commit -a -m "Testing if committing fixes it"
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
通过跳过 staging 来提交是行不通的,所以让我们先尝试 stage 吧。
user$ git add "folder with space/folder/toolbar.png"
user$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: folder with space/folder/toolbar.png
#
no changes added to commit (use "git add" and/or "git commit -a")
不起作用,所以我很难过...去问问更聪明的人。
我是 git 新手,但对 Hg 很熟悉,并且一直在阅读 this online tutorial 以帮助自己入门。
我完全有可能搞砸了一个简单的命令。
已经尝试过: 我四处寻找解决我的特定问题的方法,但运气不佳。我偶然发现了this answer,这似乎相关但并不能完全解决我的问题。
编辑:可能有趣的事情
这是让我感到困惑的部分。不久前,我已将此 repo 推送到在线存储库中。重新克隆后,repo 仍然认为文件被修改(即git status 返回相同的结果,我已经设置了git config --global core.autocrlf false 并通过运行git config --global core.autocrlf 进行验证,确实返回false)。
编辑 2:找到了修复,但问题仍然不明白 我通过简单地从系统、暂存区域中删除文件然后提交更改来设法修复存储库。 在此之后为了取回文件,我只需将其复制回来并将其提交到存储库。
这个问题虽然已经解决,但让我更加困惑。
当我在玩弄删除文件时,我注意到如果我将存储库重置为 HEAD,其最后一次提交已删除文件,git status 将表明没有任何改变并且文件未被跟踪但文件将恢复到我的工作树中。考虑到它在 git 中被标记为已删除,这很奇怪...
只有在第二次删除它之后,即使 git 不再记得它,我才设法真正删除它,以便 git reset 和 git reset --hard 不会恢复文件。
如果有人能解释一下我是如何进入这种状态的,如果这是 git 中的错误或正常行为,我将不胜感激。
我的猜想
我丢失了我使用的命令序列,但发生的事情是这样的:
该文件是Images/toolbar.png,我已经导航到Images 文件夹。
在我从文件系统中删除它之后,git 检测到这样的变化:
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: toolbar.png
# deleted: ../images/toolbar.png
#
注意images 文件夹没有大写!这是在忽略路径大小写的 Windows 中运行的。我怀疑这可能是问题的一部分......
我真的很困惑,但我的问题已经消失了。所以这篇文章只是作为一个好奇心,虽然我无法在某个地方复制它在从 SVN 转换中的行为。
【问题讨论】:
-
似乎 git 可能无法正确处理您的文件。是否可以尝试从文件夹名称中删除空格,看看是否可以解决?
-
有可能,简单没有……我试试。
-
现在,我正在尝试提取一个干净的存储库,但我怀疑这无济于事。完成后我会尝试删除空间,但存储库并不小。另外,为什么 git 会遇到路径中的空格问题?
-
我不希望它在路径名方面有问题,但是看到你的命令没有接受,我认为它值得一看。我有另一个想法。有问题的文件是二进制文件吗?你试过明确告诉 git 这个文件是二进制文件吗?
-
@nonsensical - 您使用哪个 shell 来运行 git 命令 - msysGit shell 还是 Windows 命令行?根据this 页面,在最后,它说命令需要在 Windows 命令行的双引号中。对于 msysGit shell,我相信您需要转义空格(如 *nix),例如:
foo\ bar并且不需要引号。您还可以从 repo 的根目录运行git add .以将git status列出的所有内容添加为新文件和修改后的文件。
标签: windows git png mingw msysgit