简体   繁体   中英

git alias to clean/reset all repositories in a directory

I want to clean/reset all git repositories in a directory recursively.

If I execute the following command it works as expected:

find . -name .git -type d -execdir sh -c "git clean -xdf" \;

I have problems converting the command to a git alias:

xxx = "!f() { find . -name .git -type d -execdir sh -c "git clean -xdf" ; ; }; f; "

I have tried to fix the errors such as syntax error near unexpected token ;'` however I am going in a circle with no success.

Please help me to create the alias. 10x

Here you go:

xxx = "!f() { find . -name .git -type d -execdir git clean -xdf \\; ; }; f"

A few things:

  • No need to wrap the command in sh -c , you can use it directly
  • You need to escape the \\ in \\; at the end of the find command, writing as: \\\\;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM