速查表 · Git 速查表 · Git stash 未跟踪文件(-u 与 -a)

Git stash 未跟踪文件(-u 与 -a)

git stash

是

git stash -u

是

git stash -a

是

stash 范围对比

命令已修改新文件被忽略的
git stash是否否
git stash -u是是否
git stash -a是是是

默认情况下,git stash 不会管还没被跟踪的新文件。用 -u 把新文件也一起收起来。

相关 Git 配方

常见问题

为什么普通 stash 没保存我的新文件?
普通 stash 只处理 Git 已经在跟踪的文件。有新文件时用 git stash -u。

什么时候用 -a 而不是 -u?
只有想把 .gitignore 里的文件(node_modules、.env)也收起来时才用 -a,通常 -u 就够。

怎么给带未跟踪文件的 stash 起名?
git stash push -u -m "wip: 新组件"。

别死记语法 — 用可视化生成器

在 Git 生成器里拼出准确命令

完整速查表:Git 速查表