Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git remove directory

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?

like image 637
hrickards Avatar asked Dec 22 '09 16:12

hrickards


People also ask

How do I remove one directory in git?

Deleting directory in Git To delete a directory from git repository, we can use the git command followed by rm command , -r flag and the name of your directory.

How do I remove a directory in git bash?

Delete a Directory ( rm -r ) To delete (i.e. remove) a directory and all the sub-directories and files that it contains, navigate to its parent directory, and then use the command rm -r followed by the name of the directory you want to delete (e.g. rm -r directory-name ).

How do you remove a directory?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.


2 Answers

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.
like image 54
Sk606 Avatar answered Sep 25 '22 15:09

Sk606


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.

like image 29
Brian Campbell Avatar answered Sep 24 '22 15:09

Brian Campbell