git cleanコマンドでIgnored files(無視ファイル)を削除する方法
git cleanコマンドでIgnored files(無視ファイル)も併せて削除するには-xオプション、Ignored files(無視ファイル)のみを削除するには-Xオプションを指定します。
オプションの説明
-x Don’t use the standard ignore rules (see gitignore(5)), but still use the ignore rules given with -e options from the command line. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git restore or git reset) to create a pristine working directory to test a clean build. -X Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.
-x, -Xオプションを指定した場合(-nオプションはドライラン)
$ git status --ignored 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 Ignored files: (use "git add -f ..." to include in what will be committed) d.obj $ git clean -n -x Would remove c.txt Would remove d.obj $ git clean -n -X Would remove d.obj
-x, -Xオプションを指定しない場合
$ git status --ignored 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 Ignored files: (use "git add -f ..." to include in what will be committed) d.obj $ git clean -n Would remove c.txt