Git 專案中徹底刪除某類型副檔名所有檔案
「Python uv 開發環境」通常是指使用 uv(Astral 推出的 Python 套件管理工具,類似 pip/poetry,但更快)來建立隔離環境。這會影響到工具安裝方式,但 Git 本身的命令並不依賴 Python,所以核心步驟不變。差異主要在於 如何安裝 git-filter-repo 或其他輔助工具。
uv init myproject
cd myproject
git-filter-repo在 uv 環境中安裝:
uv add git-filter-repo
這樣會把 git-filter-repo 安裝到 uv 管理的虛擬環境裡。
.m4a 的命令進入 uv shell:
uv run git filter-repo --invert-paths --path-glob '*.m4a'
這裡的差異是:
uv run 來呼叫安裝在 uv 環境裡的工具。git rm、git commit、git push)仍然直接用系統的 Git,不需要透過 uv。git filter-repo --force --invert-paths --path-glob '*.m4a'
⚠️ 注意:這會直接重寫目前 repo 的歷史,可能導致 repo 內部 packfile 與 reflog 被破壞。建議先備份或至少在另一個 clone 測試。
| 階段 | 傳統 Git | uv 環境下 |
|---|---|---|
| 移除目前版本檔案 | git rm --cached -r '*.m4a' git commit -m "Remove .m4a" |
相同 |
| 安裝工具 | pip install git-filter-repo |
uv add git-filter-repo |
| 重寫歷史 | git filter-repo --invert-paths --path-glob '*.m4a' |
uv run git filter-repo --invert-paths --path-glob '*.m4a' |
| 推送乾淨版本 | git push origin --force --all |
相同 |
.gitignore 裡加上 *.m4a,避免未來再被加入。要不要我幫你把這個流程再整理成一個 「快速命令清單」,讓你在 uv 環境裡可以直接複製貼上執行?
| File2 | File | Last Modified |
|---|---|---|
| 在 Git 資料庫中列出所有 .m4a檔案,並計算它們在 目前版本和整個歷史紀錄中所佔的位元組數 | 在 Git 資料庫中列出所有 .m4a檔案,並計算它們在 目前版本和整個歷史紀錄中所佔的位元組數 | 2:24 PM - January 12, 2026 |
| git內部完全刪除一個檔案 | git內部完全刪除一個檔案 | 2:24 PM - January 12, 2026 |