Micka Micka - 4 months ago 18
Git Question

If "git rm" doesn't work, what will?

I have tried to remove the "index.html" file for as I created it in the projects file by mistake.
I tried the git rm command but get no success.
Also tried "git reset", "git reset --hard" but nothing will do.

User Documents $ cd projects
User (master) projects $ ls
BeachParadise DasmotoProject HelloWorld RestaurantMenu index.html
Broadway HelloHtml Paris excursion
User (master) projects $ git rm index.html
fatal: pathspec 'index.html' did not match any files
User (master) projects $


Any thoughts on what I am missing here?
Thanks in advance

Answer Source

As it is explained in the first paragraph of the documentation of git rm:

Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.

Back to your case:

User (master) projects $ git rm index.html
fatal: pathspec 'index.html' did not match any files

git rm index clearly says it doesn't know anything about the file index.html. This means the file was never added to the repository or to the index (and it probably exists only in the working tree).

To remove the file from the directory simply run:

$ rm index.html

Make sure you don't need the file any more as there is no way to recover it after you ran the command above.