Dmitriy Urazov Dmitriy Urazov - 6 months ago 20
Linux Question

Removing nonexistent files from git

There is information that git status gives:

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)


I want to remove these files from my computer, because I created them accidentally

I try to perform:

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


Please help me to find and remove them!

Answer

You don´t need double slash like in "src//..."

you are using linux terminal, so you might be using bash. Try autocomplete:

rm src/H<tab><tab>

  • you write rm src/H then press tab twice, it will complete to "src/HomeBundle" then you add "/E" and press tab twice. This will help you autocomplete the path an escape chars if necessary.