Removing a weird file from git repository on mac

点点圈 提交于 2019-12-06 06:24:55

问题


I recently tried adding the OpenEars framework to my xcode project, and when I tried to commit my project to the repository I get the following error:

error: pathspec '"Framework/Icon\r"' did not match any file(s) known to git.

I have tried to find this file using the navigation tree within xcode but it doesn't exist. There is a physical file on the disk which was 0 bytes (this is most likely the problem), and I tried removing this with no affect.

I tried to navigate to the file using terminal and use git rm Icon\r but due to the \ in the name it cannot find the file:

$ git rm Icon\\r
fatal: pathspec 'Framework/OpenEars.framework/Icon\r' did not match any files

Has anyone had a similar issue or know how I can remove this file as it is stopping me from pushing any changes.


回答1:


Try cding into the directory, then start typing the following until you get to the I in Icon\r. Then press the Tab key to have the Terminal automatically complete the rest of the path. It will look like this:

git rm Framework/OpenEars.framework/Icon^M

NB: There is a space after the M. Entering in this full path does not seem to work: only allowing the Terminal to autocomplete the path for you will.

I got:

MacPro:OpenEarsDistribution mdouma46$ git rm Framework/OpenEars.framework/Icon^M 
'm 'Framework/OpenEars.framework/Icon
MacPro:OpenEarsDistribution mdouma46$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    "Framework/OpenEars.framework/Icon\r"
#



回答2:


I've just had the same issue, and found that after removing the file from the local filesystem, the following worked for me:

cd Your/Project/Directory
git add -u Path/To/Offending/File/Icon$'r'

This then allowed me to commit and remove the files from the git repository.



来源:https://stackoverflow.com/questions/12786037/removing-a-weird-file-from-git-repository-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!