我有一个文件,它自己命名为:
# file's name (both lines)
companies.yml
companies.yml
# entry in my git working tree
"test/fixtures/companies.yml\342\200\250companies.yml"
由于烦人的原因,这个特定项目的工作树充满了其他仍需要组织的文件。我想从那里获取上面的条目,但是当我尝试 git add "test/fixtures..."
或 git rm "test/fixtures..."
它失败了:
fatal: pathspec 'test/fixtures/companies.yml\342\200\250companies.yml' 不匹配任何文件
我该如何处理?
Git 状态
On branch master
# Your branch is ahead of 'production/master' by 4 commits.
#
# 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: [other files]
modified: "test/fixtures/companies.yml\342\200\250companies.yml"
最佳答案
Git 正在打印文件名的 UTF-8 编码的文字八位字节,因为它们是非 ASCII 字符,并将它们打印为八进制转义字符。但是,您的 shell 不理解它们,并且在您剪切和粘贴时将文字反斜杠和数字发送到 git 命令,因此您实际上输入了不同的文件名。
在键入 test/fixtures/companies.yml
后使用制表符补全(如果你的 shell 支持这个),这将输入实际字符或通配符代替转义符,因此 test/fixtures/companies.yml*companies.yml
。后者可能但可能不会匹配其他文件名。
当然,另一种可能性是将文件重命名为更合理的名称,然后使用 git add -u
/git add .
让 git 注意到重命名。
关于git - 从 git 中删除一个具有奇怪名称的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13250633/