git clean
git
書き方
git clean -n | git clean -fd追跡外のファイルを削除します。gitが控えを持っていないので戻せず、-fdxは.envのような無視ファイルまで消すため、先に-nで確かめます。
よく使うオプション
| オプション | 意味 |
|---|---|
| -n | dry run: list what would be deleted |
| -f | actually delete; without it git refuses |
| -d | also remove untracked directories |
| -x | also remove ignored files such as .env and node_modules |
| -X | remove only ignored files |
| -i | decide interactively |
例
git clean -ndlists the untracked files and folders that -fd would delete
git clean -fddeletes them; git never had a copy, so there is no undo
git clean -fdxalso wipes ignored files, including local .env and build output
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git clean は何をしますか。
追跡外のファイルを削除します。gitが控えを持っていないので戻せず、-fdxは.envのような無視ファイルまで消すため、先に-nで確かめます。
Q. どう打ちますか。
git clean -n | git clean -fd — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-clean