【git stash切换】

问题

当前正在修改对应某个bug,突然来了个更紧急的工作,需要保留现场,去对应更紧急的事务,git该如何操作?

1. 查看当前工作状态(确认修改)

git status

2. 保存当前工作现场(包含未提交的修改)

git stash save "WIP: Bugfix for issue #123" # 添加描述性信息

3. 确认工作区已干净

git status # 应显示"working tree clean"

4. 切换到紧急任务分支

git checkout main # 或创建新分支 git checkout -b hotfix-xxx

5. 处理紧急任务(修改、提交等)

... 进行紧急修改 ...

git add .

git commit -m "紧急修复XX问题"

6. 完成紧急任务后,回到原分支

git checkout original-branch

7. 恢复之前保存的工作现场

git stash pop # 恢复并删除最近的stash

查看存储列表

bash 复制代码
git stash list
bash 复制代码
ubuntu@ubuntuxxxxxx$ git stash list
stash@{0}: On hotfix-0529: save as leds
stash@{1}: On pdx257_fac_0523: bug for 0529 issue read

选择特定存储恢复

  1. 恢复但不删除
bash 复制代码
git stash apply stash@{1}
  1. 恢复并删除
bash 复制代码
git stash pop stash@{1}

最佳实践

bash 复制代码
[ 当前工作状态 ] 
   ↓
git stash save "描述"  → [ 安全存储箱 ]
   ↓ 
[ 干净工作区 ] → 处理紧急任务 → 提交
   ↓ 
git stash pop 
   ↓ 
[ 恢复工作现场 ]
相关推荐
wu_aceo15 分钟前
将本地项目提交到Gitee
git·gitee·提交·本地提交·上传git
跨境卫士情报站1 小时前
高阶亚马逊运营秘籍:关键词矩阵打法深度解析与应用
经验分享·教育电商
axinawang4 小时前
极域电子教室出现问题如何处理
经验分享
随便取个六字10 小时前
GIT操作 学习
git·学习
技术小赵17 小时前
优化Facebook广告投放的五大关键策略
经验分享
星源~20 小时前
tree 命令集成到 Git Bash:可视化目录结构的指南
git·单片机·物联网·嵌入式·项目开发
zhaqonianzhu21 小时前
git gerrit安装钩子
git·gerrit
这是个栗子21 小时前
【问题解决】VSCode终端中看不到Git-Bash
ide·git·vscode
悲伤小伞21 小时前
linux_git的使用
linux·c语言·c++·git
智者知已应修善业1 天前
【51单片机节日彩灯控制器设计】2022-6-11
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机