Git中stash的使用

Git中stash的使用

    • stash命令
      • [1. stash保存当前修改](#1. stash保存当前修改)
      • [2. 重新使用缓存](#2. 重新使用缓存)
      • [3. 查看stash](#3. 查看stash)
      • [3. 删除](#3. 删除)
    • 使用场景

stash命令

1. stash保存当前修改

git stash 会把所有未提交的修改(包括暂存的和非暂存的)都保存起来.

bash 复制代码
git stash

git stash save '注释'

2. 重新使用缓存

bash 复制代码
#恢复之前缓存的工作目录,会将第一个stash删除
git stash pop
#将缓存堆栈中的stash多次应用到工作目录中,但并不删除stash拷贝
git stash apply

3. 查看stash

bash 复制代码
#查看所有stash
git stash list
bash 复制代码
#查看某个具体的stash,后面加stash@{index},比如第二个 git stash show stash@{1}
git stash show -p stash@{3}

3. 删除

bash 复制代码
#清除所有stash
git stash clear
#删除stash@{index}存储,从列表中删除某个存储
git stash drop stash@{index}

使用场景

当前在开发一个功能,还未开发完,需要去另外一个分支修复一个bug

  1. git stash 保存新增功能代码到暂存区
  2. git checkout b 切换到bug分支,处理bug
  3. git checkout a 切换回开发分支
  4. git stash pop 恢复暂存区开发代码
相关推荐
麻辣璐璐7 小时前
【新手小白版】Gerrit使用教程
git·gerrit·新手
AlexMercer101212 小时前
Ubuntu从零开始配置Git
c++·git·ubuntu·gitee
胡西风_foxww1 天前
git 添加除了包含特定字符串的文件
git·字符串·文件·add·添加·特定·包含
parade岁月1 天前
Git 凭据管理器原理与多账号管理指南
git
zzzyulin1 天前
git note
git
六件套是我1 天前
【解答疑惑】git执行cherrypick后到另一个分支,然后再合并会出现问题吗?
git
sulikey2 天前
从零配置一个规范的 Python Git 仓库(适用于 Gitee / GitHub)
git·python·pycharm·gitee·github
学渣676562 天前
【面向小白】git rebase全面总结,什么时候用rebase
git
小龙报2 天前
《算法每日一题(1)--- 第31场蓝桥算法挑战赛》
c语言·开发语言·c++·git·算法·学习方法
222you2 天前
idea整合Git
git