Recursively remove .git folders
source link: https://gist.github.com/facelordgists/80e868ff5e315878ecd6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Recursively remove .git folders · GitHub
Instantly share code, notes, and snippets.
Nice! Thanks.
If you want this to work with file & directory names that have whitespace in them you can change the delimiter to '\n':
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs -d '\n' rm -rf
Since MacOS High Sierra 10.13+ has an installed xargs that doesn't support the -d
argument, you can use -0
in its place.
( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" ) | xargs -0 rm -rf
Thanks. I added .gitattributes
`( find . -type d -name ".git" && find . -name ".gitignore" && find . -name ".gitmodules" && find . -name ".gitattributes" ) | xargs rm -rf
I see a couple of problems here.
-
Separating the
find
commands with&&
means that the subsequent ones will only run if the last one had an exitcode == 0. That might not always be the case. -
Lots of forking (
find
->find
->find
->find
->xargs
). That could be simplified and done without any pipes:
find . \( -name ".git" -o -name ".gitignore" -o -name ".gitmodules" -o -name ".gitattributes" \) -exec rm -rf -- {} +
Great! Thank you!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK