从git中删除不存在的文件

时间:2016-06-07 20:40:26

标签: linux git symfony unix ubuntu

有git status提供的信息:

git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)

Untracked files:
(use "git add <file>..." to include in what will be committed)

"src/HomeBundle/Entity/\320Apartments.php"
"src/HomeBundle/Repository/\320ApartmentsRepository.php"
"src/HomeBundle/Resources/config/doctrine/\320Apartments.orm.yml"

nothing added to commit but untracked files present (use "git add" to track)

我想从我的计算机中删除这些文件,因为我意外地创建了这些文件

我尝试执行:

git rm "src/HomeBundle/Entity/\320Apartments.php"
fatal: pathspec 'src/HomeBundle/Entity/\320Apartments.php' did not match any files

git rm '"src/HomeBundle/Entity/\320Apartments.php"'
fatal: pathspec '"src/HomeBundle/Entity/\320Apartments.php"' did not match any files

rm '"src/HomeBundle/Entity/\320Apartments.php"'
rm: cannot remove ‘"src/HomeBundle/Entity/\\320Apartments.php"’: No such file or directory

rm "src/HomeBundle/Entity/\320Apartments.php"
rm: cannot remove ‘src/HomeBundle/Entity/\\320Apartments.php’: No such file or directory

git rm '"src//HomeBundle//Entity//\320Apartments.php"'
fatal: pathspec '"src//HomeBundle//Entity//\320Apartments.php"' did not match any files

git rm "src//HomeBundle//Entity//\320Apartments.php"
fatal: pathspec 'src//HomeBundle//Entity//\320Apartments.php' did not match any files

rm '"src//HomeBundle//Entity//\320Apartments.php"'
rm: cannot remove ‘"src//HomeBundle//Entity//\\320Apartments.php"’: No such file or directory

请帮我找到并删除它们!

3 个答案:

答案 0 :(得分:1)

你不需要像“src //...”

中的双斜线

你正在使用linux终端,所以你可能正在使用bash。尝试自动填充:

rm src/H<tab><tab>

  • 你写rm src/H然后按Tab键两次,它将完成“src / HomeBundle”然后你添加“/ E”并按Tab键两次。这将帮助您在必要时自动填充转义字符的路径。

答案 1 :(得分:1)

您可以运行'git clean -f'从工作目录中删除所有未跟踪的文件。添加'-d&#39;也可以选择删除目录。您也可以使用&#39; git clean -n&#39;检查将要删除的内容(所谓的&#39;干运行&#39;)。

答案 2 :(得分:0)

使用git rm file_name命令删除文件跟踪。