【问题标题】:Trouble removing oddly named files from github repo从 github 存储库中删除奇怪命名的文件时遇到问题
【发布时间】:2013-12-31 17:01:35
【问题描述】:

我最近在我的 github 存储库中获得了几个损坏的文件。我已经从我的主机中删除了它们,但是我无法用 git 删除它们,因为它们的名字弄乱了。它们在 git status 下是这样显示的

# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    "\001\006@@x\021@8"
#   deleted:    "path/to/\001\006@@x\021@8"
#

我试过了

git rm "path/to/\001\006@@x\021@8"

但我得到了错误

fatal: pathspec 'path/to/\001\006@@x\021@8' did not match any files

知道如何从 repo 中正确删除这些文件吗?

【问题讨论】:

    标签: git github corrupt rm


    【解决方案1】:

    删除该文件的问题不是 Git,问题是在 shell 中以正确的方式告诉 Git。由于特殊符号,这很棘手,但您可以这样做:

    git rm $(echo -e "path/to/\001\006@@x\021@8")
    

    顺便说一句,在您的具体情况下,根据您的git status 的输出,您实际上可以跳过git rm 并简单地跳过git commit -a-a--all 标志使 git 提交所有挂起的更改,包括未暂存的更改和已删除的文件。

    【讨论】:

      【解决方案2】:
      git rm -- "path/to/\001\006@@x\021@8"
      

      以下 SO 帖子有助于理解双连字符 (--) 选项。

      Deleting a badly named git branch

      【讨论】:

      • 内容丰富,解释清楚,完全没有抓住重点 ;-) git rm -- somepath 在文件名以 - 开头的情况下会有所帮助。 OP的问题是不同的。
      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 2012-03-04
      • 2014-01-04
      • 1970-01-01
      • 2013-09-23
      相关资源
      最近更新 更多