Git:git cleanコマンドでドライラン(dry run)して削除対象ファイルを確認する方法

スポンサーリンク

git cleanコマンドでドライラン(dry run)して削除対象ファイルを確認する方法

git cleanコマンドでドライラン(dry run)して削除対象ファイルを確認するには-nオプションを指定します。

 

オプションの説明

 -n, --dry-run
     Don’t actually remove anything, just show what would be done.

 

-nオプションを指定した場合(ファイルは削除されない)

$ git status -s
M  a.txt
A  b.txt
?? c.txt
?? d.txt
$ git clean -n
Would remove c.txt
Would remove d.txt
$ git status -s
M  a.txt
A  b.txt
?? c.txt
?? d.txt

 

-nオプションを指定しない場合(ファイルは削除するには-fオプションを指定)

$ git status -s
M  a.txt
A  b.txt
?? c.txt
?? d.txt
$ git clean
fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean
$ git clean -f
Removing c.txt
Removing d.txt
$ git status -s
M  a.txt
A  b.txt