48

I've got a repository on GitHub (http://github.com/hrickards/PHP-Crypto) for a little project me and a couple of others are working on. My development environment is Aptana Studio, and I use the EGit plugin as Aptana is basically Eclipse underneath. Today the designer sent the HTML and CSS for the website with the images in a folder named img. Previously the images were in a folder called images. Thinking nothing of it and being too lazy to update the CSS and HTML, I simply kept the images in the img directory and commited to Git. However, the GitHub web interface shows both the img and images directories, with the images directory being empty. I've tried deleting the images directory with git rm -r images and git rm images, and even mkdir images; git add images; git rm -r images but whatever I try I get the same result: fatal: pathspec 'images' did not match any files.

Has anyone got any advice on how to remove images, or am I misunderstanding Git or something?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
hrickards
  • 1,061
  • 2
  • 9
  • 20

4 Answers4

79

This is what I use, and I think you'll want to as well. It's close to the other answers, but instructs git to NOT change the local files.

git rm -r -f --cached DirectoryName
  • -r : recursive
  • -f : force
  • --cached : apply ONLY to index (staging area). Git leaves the local copies alone.
Sk606
  • 2,182
  • 1
  • 21
  • 14
  • 1
    `git rm -r -f .` deleted all my local copies of files excluding files declared in `.gitignore`. After a heady and sweety hour I managed to recover them with `git checkout HEAD .`. So use this command carefully. Of course I had forgotten the `--cached` argument part. – Hmerman6006 Dec 28 '20 at 22:28
41

Git does not store any information about the directory, just the files within it. So, you cannot add or remove directories themselves; if you say git add images, Git will add all of the files within that directory (that don't match the ignore list).

Generally, the only way for there to be an empty directory is if it actually contains a file, usually a hidden file like .gitignore.

You said that you see an images directory on GitHub, but I'm not seeing it in the repo that you linked to. Are you sure it's there, and not just an empty directory on your disk? If it's just an empty directory on your disk, you can just remove it using rm images; Git doesn't need to know about it.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
  • You're right - it's not there now. It definitely wasn't on my disk, so I can only assume my browser, Chrome, had cached the page or something even when I refreshed it. It has a habit of doing that. Thanks for the help anyway! – hrickards Dec 22 '09 at 17:33
  • @hrickards Just a tip, if you want to force chrome (I think it works in other browsers too but I didn't test it) to reload the page completely, press [CTRL]+F5. – michael_ Jul 22 '14 at 19:14
38

try this:

git rm -r -f DirectoryName
Viccari
  • 9,029
  • 4
  • 43
  • 77
nizar ouerghi
  • 1,721
  • 2
  • 14
  • 12
3

The linked GitHub repository does not show the images directory.

Git does not store empty directories for technical reasons, so just try rm images and remove the images directory from your local directory hierarchy.

Andrew
  • 570
  • 4
  • 11
  • Hi, as said above I think Chrome must have cached the page even when I F5'ed it or something. Thanks for the help anyway! – hrickards Dec 22 '09 at 18:19