git rm 带空格的文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11855517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:20:32  来源:igfitidea点击:

git rm file name with space

git

提问by J W

I tried merging with the command line for a project in Xcode and I think a file needs to be removed. It is a file that exists in the branch I was merging from, but not the branch I was merging into. The problem is it has a space in the name:

我尝试在 Xcode 中与一个项目的命令行合并,我认为需要删除一个文件。这是一个存在于我正在合并的分支中的文件,但不是我正在合并的分支。问题是它的名称中有一个空格:

TestService/TestService copy-Info.plist

How do I remove that file? thanks!

如何删除该文件?谢谢!

回答by Keith Thompson

The same way you'd use rmto remove such a file: quote the name:

rm删除此类文件的方法相同:引用名称:

git rm "TestService/TestService copy-Info.plist"

or

或者

git rm 'TestService/TestService copy-Info.plist'

or

或者

git rm TestService/TestService\ copy-Info.plist

Depending on your shell and the names of other files, tab completion may help with this. Typing

根据您的 shell 和其他文件的名称,制表符完成可能对此有所帮助。打字

$ git rm TeTab

$ git rm TeTab

will likely complete the directory name:

可能会完成目录名称:

$ git rm TestingService/

$ git rm TestingService/

Then typing part of the file name and another tab:

然后键入文件名的一部分和另一个选项卡:

$ git rm TestService/TeTab

$ git rm TestService/TeTab

will complete the filename, including an inserted \to escape the space character:

将完成文件名,包括插入\以转义空格字符:

$ git rm TestService/TestService\ copy-Info.plist

$ git rm TestService/TestService\ copy-Info.plist

But tab completion usually only expands a unique prefix based on all the files available, so this may or may not work.

但是制表符补全通常只根据所有可用文件扩展一个唯一的前缀,所以这可能会也可能不会。

回答by Blender

You can either quote the filename:

您可以引用文件名:

git rm "TestService/TestService copy-Info.plist"

Or escape the space:

或者逃离空间:

git rm TestService/TestService\ copy-Info.plist

回答by Adrian

If you use Ubuntu sometimes you need to use git rm --cached -r "TestService/TestService copy-Info.plist"

如果您有时使用 Ubuntu,则需要使用 git rm --cached -r "TestService/TestService copy-Info.plist"

回答by Hoshts

Have your tried to add quotes to the filename? "TestService/TestService copy-Info.plist"I'm not 100% sure how it works with Git.

您是否尝试在文件名中添加引号?"TestService/TestService copy-Info.plist"我不是 100% 确定它如何与 Git 一起使用。