标签:情况下 mqc efs release and 结果 mod 一个 stash
背景:
实际开发过程中,经常可能遇到的一个问题,当你在dev分支上正开发得happy的时候;突然来了个线上bug,得赶紧从release分支上切一个bugfix分支来解决线上问题,这个时候,正在开发的东西,就得暂存了
之前对于Git只是简单的了解了下,只处于入门的会用级别,遇到上面这个问题,采取的是一个比较笨的方案:
# 1. 将当前改动保存,并提交一个tmp commit
git add .
git commit -m ‘tmp save‘
## 注意上面只是提交到本地,没有推送到远端仓库
# 2. 开始bugfix
## 然后切换到release 分支,并获取最新代码
git checkout release
git pull origin release
## 新建bugfix分支
git checkout -b bugfix
... # 开始干活
# 3. 回到原来分支,继续干活
git checkout dev
git log
git reset --soft commit号
虽然上面这样也可以曲线救国,但是在了解到Git stash之后,就简单多了,不需要commit和reset
将当前改动暂存,恢复到上一次commit号对应的状态
git stash
上面执行完毕之后,当前所有的改动会被暂存,然后工作区变得干净,使用git status
会发现没有修改
查看暂存的列表
git stash list
如果需要恢复之前的改动,执行
git stash pop
下面是个人的一个项目的测试结果
? git status
On branch master
Your branch is up-to-date with ‘origin/master‘.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: spring-rabbit/src/test/java/com/git/hui/rabbit/spring/SprintUnit.java
modified: spring-rabbit/src/test/java/com/git/hui/rabbit/spring/fac/FacMQConsumer.java
no changes added to commit (use "git add" and/or "git commit -a")
? git stash
Saved working directory and index state WIP on master: 8a96c7b 添加基于配置的消费者方式
HEAD is now at 8a96c7b 添加基于配置的消费者方式
? git stash list
stash@{0}: WIP on master: 8a96c7b 添加基于配置的消费者方式
? git status
On branch master
Your branch is up-to-date with ‘origin/master‘.
nothing to commit, working tree clean
? git stash pop
On branch master
Your branch is up-to-date with ‘origin/master‘.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: spring-rabbit/src/test/java/com/git/hui/rabbit/spring/SprintUnit.java
modified: spring-rabbit/src/test/java/com/git/hui/rabbit/spring/fac/FacMQConsumer.java
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (fa73ca947d591003cd46a49f6d657cce43756d1a)
? git stash list
? git status
On branch master
Your branch is up-to-date with ‘origin/master‘.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: spring-rabbit/src/test/java/com/git/hui/rabbit/spring/SprintUnit.java
modified: spring-rabbit/src/test/java/com/git/hui/rabbit/spring/fac/FacMQConsumer.java
no changes added to commit (use "git add" and/or "git commit -a")
简单的使用场景下,需要暂存时,直接输入 git stash
命令即可;需要恢复执行 git stash pop
;
如果出现多次的工作区暂存,会怎样?
两次暂存之后: (最近暂存的,序号最小)
? git stash list
stash@{0}: WIP on master: 8a96c7b 添加基于配置的消费者方式
stash@{1}: WIP on master: 8a96c7b 添加基于配置的消费者方式
应用某次暂存:
git stash apply stash@{1}
执行apply只是会恢复当时暂存的内容,但是不会删除,如果需要删除指定stash,可以执行
git stash drop stash@{1}
在某些情况下,你可能想应用储藏的修改,在进行了一些其他的修改后,又要取消之前所应用储藏的修改。Git没有提供类似于 stash unapply 的命令,但是可以通过取消该储藏的补丁达到同样的效果:
git stash show -p stash@{0} | git apply -R
一灰灰的个人博客,记录所有学习和工作中的博文,欢迎大家前去逛逛
尽信书则不如,已上内容,纯属一家之言,因个人能力有限,难免有疏漏和错误之处,如发现bug或者有更好的建议,欢迎批评指正,不吝感激
标签:情况下 mqc efs release and 结果 mod 一个 stash
原文地址:https://www.cnblogs.com/yihuihui/p/9157321.html