Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to remove my .git folder and 'rm -r .git --force' is not working

Tags:

bash

rm

rm -r .git
rm -r .git --force

I get the following and there seems to be a never ending supply after I enter 'yes' and move to the next.

override r--r--r--  redacted/staff for .git/objects/95/90087aa4b351e278e6e53ff6240045ab2db6d1?
like image 371
seamus Avatar asked Mar 24 '19 04:03

seamus


People also ask

How do I force delete a .git folder?

Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains. This Git repo remove command also allows you to delete the Git repo while allowing all of the other files and folder to remain untouched.

What happens if I delete .git folder?

The folder is created when the project is initialized (using git init ) or cloned (using git clone ). It is located at the root of the Git project repository. If we delete the . git folder, the information saved by Git will be lost, and the directory will no longer act as a Git repository.

Why is there a .git folder in my project how did it get there why is it hidden and what does it do?

The . git folder is hidden to prevent accidental deletion or modification of the folder. The version history of the code base will be lost if this folder is deleted. This means, we will not be able to rollback changes made to the code in future.


3 Answers

Analysis and explanation:

The message override r--r--r-- ...? is seen in some versions of the rm command when you try to delete a file or files with the rm command that have write access removed.

To reproduce:

▶ mkdir -p foo/{bar,baz} ; touch foo/bar/qux 
▶ chmod -R -w foo 
▶ find foo -ls 
4305147410        0 dr-xr-xr-x    4 alexharvey       wheel                 128 24 Mar 18:19 foo
4305147412        0 dr-xr-xr-x    2 alexharvey       wheel                  64 24 Mar 18:19 foo/baz
4305147411        0 dr-xr-xr-x    3 alexharvey       wheel                  96 24 Mar 18:19 foo/bar
4305147413        0 -r--r--r--    1 alexharvey       wheel                   0 24 Mar 18:19 foo/bar/qux

Now if you try to delete these files you'll be asked if you really want to override this file mode:

▶ rm -r foo
override r-xr-xr-x  alexharvey/wheel for foo/baz? 

Note also that if you are on Mac OS X or other BSD variant, as appears to be the case, then you have specified the --force argument incorrectly by adding it to the end of the command line, where it will be interpreted as the name of an additional file to delete.

But even if I correct that, -f still can't override r--r--r--. Instead, you would see this:

▶ rm -rf foo       
rm: foo/baz: Permission denied
rm: foo/bar/qux: Permission denied
rm: foo/bar: Permission denied
rm: foo: Directory not empty

The fix:

To fix this, firstly restore the write permission within the folder:

▶ chmod -R +w foo

Then rm -r should work fine:

▶ rm -r foo
▶ ls foo 
ls: foo: No such file or directory

See also:

  • this related question at Unix & Linux Stack Exchange.
  • source code for BSD rm here.
like image 165
Alex Harvey Avatar answered Oct 19 '22 00:10

Alex Harvey


if you want to delete directories in git, just log in to sudo:

$ sudo rm -r file-name

like image 22
Edward Leung Avatar answered Oct 18 '22 23:10

Edward Leung


rm -rf .folder 

does the trick without spending extra time setting parameters

like image 1
Sergio Bost Avatar answered Oct 19 '22 00:10

Sergio Bost