# ===== CodeLab: Git stash 暂存技巧 =====
# 来源: https://aoerliang.dpdns.org/articles/git-stash
# 以下代码片段按文章出现顺序拼接, 共 5 段

# ----- 片段 1 (bash) -----
# 保存当前所有改动
git stash push -m "登录页样式进行中"

# 查看暂存栈
git stash list
# stash@{0}: On main: 登录页样式进行中

# 恢复最近一次 stash 并把它从栈中移除
git stash pop

# 恢复但不移除(可能想多次使用)
git stash apply stash@{0}

# ----- 片段 2 (bash) -----
# 查看最近一个 stash 改动了哪些文件
git stash show stash@{0}

# 查看完整 diff(加 --stat 只看统计)
git stash show -p stash@{1}

# ----- 片段 3 (bash) -----
# 连未跟踪文件一起存
git stash push -u -m "含新文件"

# 连被忽略的文件(.gitignore 里的)也存
git stash push -a -m "全部带走"

# ----- 片段 4 (bash) -----
# 删除指定的 stash
git stash drop stash@{0}

# 清空整个暂存栈
git stash clear

# 误删了?用 reflog 找回
git fsck --unreachable | grep commit

# ----- 片段 5 (bash) -----
git stash push -u -m "支付功能进行中"
git checkout -b hotfix/timeout main
# ...修复并提交...
git checkout feature/payment
git stash pop
