I'd like to find a regex-way of using git clean.
Without regex:
git clean -dfx --exclude=".idea/"
With regex (tried; not working):
git clean -dfx --exclude='(.*\/)*(\.idea\/.*)(.*)'
git clean -dfx --exclude="(.*\/)*(\.idea\/.*)(.*)"
git clean -dfx --exclude=r'(.*\/)*(\.idea\/.*)(.*)'
git clean -dfx --exclude=r"(.*\/)*(\.idea\/.*)(.*)"
How do you use git clean with regex?
git cleanhas no support for regular expressions.A workaround would be something like this:
Breakdown of things happening here:
git clean -nproduces a list of files that would be removed ifgit cleanwould be executed (you can use flags like-d,-xor-Xhere too)-ndry-run (do not actually do anything)cut -f3 -d' 'cuts the third field from those matches (delimited by an whitespace)-f3third field-d' 'use whitespace as the delimitergrep -v -E --color=never '<PATTERN>'-vinvert the matches from grep-Einterpret PATTERN as an extended regular expressioncolor=neverto prevent coloredgrepoutput to mess with the following commands (may be omitted)'<PATTERN>'a regular expressionifne git cleanwill pipe the file list (if there are files) togit cleanifnea utility function from moreutils (installable via homebrew or other package managers)git cleanwill take this list and clean the files (use-nfirst to make sure no files get removed that you did not expect)That is the magic of small command line programs each doing a simple specific task