git - 从 git 中删除一个具有奇怪名称的文件

标签 git

我有一个文件,它自己命名为:

# 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/

相关文章:

ruby-on-rails - Rails - .gitignore 没有 "Mate"命令 - 使用 InstantRails?

git - Pod 不可见

css - 在新机器上克隆元素后,twitter bootstrap rails CSS 未加载

eclipse - 项目不受版本控制 - 从 EGit 存储库导入

git - 如何将 Clearcase UCM/Base VOB 迁移到具有完整历史记录的 Git(Stash)?

git - 如何在保持深度为 1 的同时在标签中初始化子模块

git - 如何覆盖 .gitignore 中的规则集

git - 您如何以自动化方式管理团队中的 git 预提交 Hook ?

css - heroku 和 django : server doesn't load staticfiles

git - docker build 命令使用 ssh url 到 git repo : Permission denied