Reputation: 1100
I've done this 100s of times. I deleted a file from a directory and then run git status which looks fine.
# 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: themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php
#
Then I run git rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php and receive an error message
error: pathspec 'themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php' did not match any file(s) known to git.
git status "knows" about the file but but git rm doesn't and won't remove it. I'm stuck and how do I solve this?
Upvotes: 3
Views: 9858
Reputation: 3631
this append when you remove the files an directories not using git's git rm
command.
I did git stash
It restored the files
that I had deleted using rm
instead of git rm
.
I fact I first did a checkout of the last hash, but I do not believe this is required.
Upvotes: 0
Reputation: 108101
A quick and dirty solution would be to add back the file and use
git rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php
to remove it.
git rm
removes the file from the filesystem too, so you don't need (and in general you shouldn't) to manually remove the file.
EDIT
A cleaner way to do so, would be to make git to notice the missing file using
git add -u
or
git commit -a
From the doc of git-add
, here's the description of the -u
option
Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.
and here's the one for the -a
option of git-commit
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about are not affected.
Upvotes: 10
Reputation: 3765
The git rm man page describes several ways of removing files no longer present in the working tree.
In the future, it is simpler to delete the file with git rm
than to delete it separately.
Upvotes: 1