I am on the git root folder, whose absolute path is /path/project/
. The folder structure is:
/path/project
---- libs/alib (actual library folder)
---- exec/alib_link (symbolic link to the actual alib folder)
I can remove the symbolic link with git rm
using relative path: git rm exec/alib_link
But using absolute path causes git to try deleting my original folder instead
git rm /path/project/alib_link
fatal: not removing /path/project/libs/alib recursively without -r
How can I force git to remove the symbolic link using absolute path without causing it to try deleting my original directory?
The best I've been able to come up with for this is a Git alias using Perl:
rma = "!f() { r=`echo $1 | perl -e 'use Path::Class; $a=file(<>); $r=$a->relative(\".\"); print $r;'`; git rm $r; }; f"
You can then do
git rma /path/project/alib_link
from anywhere within your repository, with the desired effect.
How it works:
rma
calls the shell function f
.$1
(the argument to git rma
) to Perl using echo
. Perl reads it in using <>
.$a
is used to refer to the file you're trying to remove using its absolute path.$r
is used to refer to the file you're trying to remove using its path relative to the working directory. Note that Git aliases that run shell commands use the repository root as their working directory.$r
.git rm $r
to actually remove the file. Note that this also runs in the working directory (i.e. the repository root).A more concise version might be:
rma = "!f() { git rm `perl -e 'use Path::Class; print file($ARGV[0])->relative(\".\");' $1`; }; f"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With