bashrm

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


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?

Solution

  • 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: