git - 我如何运行 `git mv --index` (--index 选项在 git mv 上不可用)

标签 git invalid-characters

我有一个 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/

相关文章:

git - 如何使 git repo 的子文件夹与另一个 git repo 的子文件夹保持同步

Git,删除存储库

c++ - cin.clear() 不重置 cin 对象

nodemon - 如何从 package.json 在 Windows 中运行 nodemon

windows - Windows 环境变量名称和值的有效字符是什么?

android - 使用 Android XmlPullParser 解析无效的符号

git - 高级 git 场景

git - 需要从之前的提交中获取一些代码——Sourcetree

git - Aptana、SourceTree 和 Git - 初学者

python - 在 Python 中过滤字符串