Cant rm folder with GIT rm?
Asked Answered
R

5

12

I want to remove an entire directory with GIT ... each time I keep getting the same error and don't understand why this is happening.

I want to remove the "blue_white" folder ...

├── css
│   ├── design.css
│   └── red_white.css
├── images
│   ├── blue_white
│   │   ├── accordion-button.png
│   │   ├── accordion-shadow.png
│   │   ├── button1.png
│   │   ├── oem-slide-shadow.png
│   │   └── truncate-arrow.png
│   └── red_white
│       ├── accordion-shadow.png
└── pages.xml

When I do this ...

git rm -r blue_white/

I get this ...

fatal: pathspec 'f04/blue_white/' did not match any files
Reassure answered 13/9, 2012 at 13:54 Comment(0)
O
25
  1. $ rm -r images/blue_white/
  2. $ git rm -r images/blue_white/
  3. $ git commit -m 'Remove images/blue_white directory'
Oust answered 13/9, 2012 at 14:6 Comment(2)
Do you want to completely remove images/blue_white/ directory or just take it out from git control?Oust
Still getting the same problem in step 2 (git rm -r images/blue_white/) Error: fatal: pathspec ...........Hemocyte
A
4

It sounds like you are in the f04 directory, not the images directory.

Amos answered 13/9, 2012 at 14:8 Comment(0)
W
1

This works

git rm -r --cached blue_white 

Then do a commit.

Windbroken answered 16/8, 2013 at 9:55 Comment(0)
B
1

I just noticed that git rm deletes a directory when the last remaining file is removed.

With only myFile residing in myDir, after performing
git rm myDir/myFile
directory myDir was gone. Note that I didn't use the -r option.

Bookerbookie answered 24/2, 2014 at 15:24 Comment(0)
R
0

Managed to do this in a single step:

git rm -rf $parent_dir

After that, the directory and all its contents (subdirectories and files) are deleted, and git status also shows that deleted: $parent_dir_files is ready to be committed.

Revenue answered 5/4, 2022 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.