git cleanコマンドで除外パターンを指定して削除する方法
git cleanコマンドで除外パターンを指定して削除するには-eオプションを指定します。
オプションの説明
-e <pattern>, --exclude=<pattern> Use the given exclude pattern in addition to the standard ignore rules (see gitignore(5)).
-eオプションを指定した場合(-nオプションはドライラン)
$ git status On branch master Changes to be committed: (use "git restore --staged ..." to unstage) modified: a.txt new file: b.txt Untracked files: (use "git add ..." to include in what will be committed) c.txt d.txt e.md $ git clean -n -e "*.txt" Would remove e.md $ git clean -n -e "*.md" Would remove c.txt Would remove d.txt
-eオプションを指定しない場合
$ git status On branch master Changes to be committed: (use "git restore --staged ..." to unstage) modified: a.txt new file: b.txt Untracked files: (use "git add ..." to include in what will be committed) c.txt d.txt e.md $ git clean -n Would remove c.txt Would remove d.txt Would remove e.md