跳轉至

建立 2024-01-01 更新 2026-09-15

git stash

git stash 把目前 workspace 與 staging 的修改暫時收起來,讓工作區變乾淨。典型情境:你改到一半,必須先 pull、切分支或修緊急 bug。

git clean 則是刪從未追蹤的檔,兩者不要混用。

git stash

把修改收進 stash:

git stash

列出所有暫存:

git stash list

取回最近一筆,但留在清單裡:

git stash apply

取回並刪除該筆:

git stash pop

刪除指定筆:

git stash drop stash@{n}

未追蹤的新檔預設不一定會進 stash,需要時用 git stash -u。

git clean

先預覽會刪哪些未追蹤檔:

git clean -n

真的刪除檔案(無法靠 Git 復原):

git clean -f

連未追蹤目錄一起刪:

git clean -fd

差異

指令 作用 區域
git stash 保存已追蹤的修改,之後還能拿回 workspace、staging
git clean 刪掉未追蹤檔 workspace