红穆笔记

git clean

從工作區刪除未被 Git 跟蹤的文件

100% 瀏覽器本地處理 0 數據上傳

常用示例

刪除未跟蹤的文件

git clean

交互式刪除未跟蹤的文件

git clean {{[-i|--interactive]}}

顯示將被刪除的文件(模擬運行,不實際刪除)

git clean {{[-n|--dry-run]}}

強制刪除未跟蹤的文件

git clean {{[-f|--force]}}

強制刪除未跟蹤的目錄

git clean {{[-f|--force]}} -d

刪除未跟蹤的文件(包括被忽略的文件,在 `.gitignore` 和 `.git/info/exclude`的文件)

git clean -x

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Remove files not tracked by Git from the working tree. More information

Interactively delete untracked files

git clean {{[-i|--interactive]}}

Show which files would be deleted without actually deleting them

git clean {{[-n|--dry-run]}}

Immediately force deletion of all untracked files

git clean {{[-f|--force]}}

Delete untracked [d]irectories

git clean {{[-f|--force]}} -d

Delete only untracked files matching specific paths or `glob` patterns

git clean {{[-f|--force]}} -- {{path/to/directory}} '{{*.ext}}'

Delete untracked files except those matching the given patterns

git clean {{[-f|--force]}} {{[-e|--exclude]}} '{{*.ext}}' {{[-e|--exclude]}} {{path/to/directory}}/

Delete untracked files and e[x]cluded files (those listed in `.gitignore` and `.git/info/exclude`)

git clean {{[-f|--force]}} -x

命令信息

命令名git clean
用途從工作區刪除未被 Git 跟蹤的文件
適用平臺通用
示例數量6 條
官方文檔https://git-scm.com/docs/git-clean
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

git clean 命令是做什麼的?

從工作區刪除未被 Git 跟蹤的文件

git clean 怎麼用?

頁面按場景列出了6 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

git clean 最常用的操作是什麼?

刪除未跟蹤的文件:git clean

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。