git clean

git

書き方

git clean -n | git clean -fd

追跡外のファイルを削除します。gitが控えを持っていないので戻せず、-fdxは.envのような無視ファイルまで消すため、先に-nで確かめます。

よく使うオプション

オプション意味
-ndry run: list what would be deleted
-factually delete; without it git refuses
-dalso remove untracked directories
-xalso remove ignored files such as .env and node_modules
-Xremove only ignored files
-idecide interactively

git clean -nd

lists the untracked files and folders that -fd would delete

git clean -fd

deletes them; git never had a copy, so there is no undo

git clean -fdx

also 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