Git:临时切换分支保存当前工作


Git:临时切换分支保存当前工作

方案一:Git Stash 暂存功能

1、 保存当前工作

# 或使用简短命令
git stash

# 添加描述信息
git stash push -m "开发登录验证逻辑"

# 查看stash列表
git stash list
# stash@{0}: On feature/login: WIP: 登录功能开发中
# stash@{1}: On main: 临时修改

# 查看stash内容
git stash show -p stash@{0}

2、切换分支

# 1. 切换回主分支或其他分支
git checkout main

3、恢复工作

# 1.恢复最近一次stash
git stash pop

方案二:创建临时提交

# 1. 提交当前不完整的工作
git add .
git commit -m "WIP: 临时保存当前进度"

# 2. 切换到其他分支
git checkout main

# 3. 完成任务后切回
git checkout feature/login

# 4. 撤销临时提交但保留修改
git reset HEAD~1
# 或保留在提交中但修改消息
git commit --amend -m "feat: 完成登录功能"
posted @ 2026-03-02 23:21  比特向阳  阅读(0)  评论(0)    收藏  举报