我有一个 git 存储库,其中包含一个在 Windows 下名称无效的文件:
foo/bar/baz|quux
由于我想在不重新启动的情况下解决问题,因此我尝试了以下命令:
git clone -n ssh://example.com/home/me/repo.git
git mv "foo/bar/baz|quux" "foo/bar/baz-quux"
但我得到的是:
fatal: bad source, source=foo/bar/baz|quux, destination=foo/bar/baz-quux
我最终在 Linux 下运行了该命令,并使用了 checkout 的存储库( git clone
,没有 -n
),并且 id 工作得很好,所以我猜 fatal
是这样的。错误是由于该文件未在 Windows 下 checkout (因为我无法 checkout )。
那么我将如何运行 git mv --index "foo/bar/baz|quux" "foo/bar/baz-quux"
所以它只修改索引,而忽略文件不在磁盘上的事实?选项--index
不适用于 git mv
,我尝试过 -f
但它失败并显示相同的消息。
最佳答案
我找到了解决方案:
git clone -n ssh://example.com/home/me/repo.git
# Create foo/bar since the checkout -n didn't create it
mkdir -p foo/bar/
# Create the new file
git show "foo/bar/baz|quux" > "foo/bar/baz-quux"
git add "foo/bar/baz-quux"
# Remove the old file in the index
git rm --cached "foo/bar/baz|quux"
git commit -m "Moved file with invalid name."
请注意,这不允许轻松移动具有无效名称的目录 - 您必须 git show origninal-name > new-name
每个文件(尽管一个小的 shell 脚本可以如果有很多文件,请提供帮助)。
关于git - 我如何运行 `git mv --index` (--index 选项在 git mv 上不可用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19001983/