Git Stash紧急处理问题,需要切分支
在开发过程中,大家都遇到过bug,并且有些bug是需要紧急修复的。
当开发人员遇到这样的问题时,首先想到的是我新切一个分支,把它修复了,再合并到master上。
当时问题来了,你当前正在开发的分支上面,还有未提交的代码,你又不想把代码提交了,怎么办呢?
git提供了stash功能,把当前工作目录现场给存储起来,等修复完bug,再切回来。
比如,我当前在dev分支上,我修改了hello.py文件
wangkongming@Vostro ~/babytree/github/test_git $ git st
On branch dev
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: hello.py
no changes added to commit (use "git add" and/or "git commit -a")
执行git stash命令后,再查看分支状态
wangkongming@Vostro ~/babytree/github/test_git $ git stash
Saved working directory and index state WIP on dev: a9c8783 *modify dev 1
HEAD is now at a9c8783 *modify dev 1
wangkongming@Vostro ~/babytree/github/test_git $ git st
On branch dev
nothing to commit, working directory clean
从master上新切分支hot_fix来处理bug
wangkongming@Vostro ~/babytree/github/test_git $ git co master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
wangkongming@Vostro ~/babytree/github/test_git $ git co -b hot_fix
Switched to a new branch 'hot_fix'
修改了test/readme.txt文件
wangkongming@Vostro ~/babytree/github/test_git $ git st
On branch hot_fix
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: test/readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
添加到版本库,提交
wangkongming@Vostro ~/babytree/github/test_git $ git add .
wangkongming@Vostro ~/babytree/github/test_git $ git ci -m 'fix bug'
[hot_fix 7b3948b] fix bug
1 file changed, 1 insertion(+)
切回master,合并hot_fix分支
wangkongming@Vostro ~/babytree/github/test_git $ git co master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
wangkongming@Vostro ~/babytree/github/test_git $ git merge hot_fix
Updating 1ebc483..7b3948b
Fast-forward
test/readme.txt | 1 +
1 file changed, 1 insertion(+)
ok,到此,这个紧急的bug,已经合并到master分支上。现在可以回到dev分支上继续开发了。
用stash list来查看已经存储的工作现场。
wangkongming@Vostro ~/babytree/github/test_git $ git stash list
stash@{0}: WIP on dev: a9c8783 *modify dev 1
如何恢复工作现场呢?
- 第一种方案,用
git stash apply恢复,但是恢复后,stash内容不删除,需要用git stash drop来删除 - 第二种方案,用
git stash pop,恢复的同时把stash内容也删除了。
wangkongming@Vostro ~/babytree/github/test_git $ git stash pop
On branch dev
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: hello.py
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (d658ee3001b54567337fe7fe522e6fd813fd73ae)
总结###
修复bug时,通过新建分支,去修复bug,然后合并分支,删除分支。
当前工作没有完成,先把现场git stash存储一下,去修复bug,修复完后,在git stash pop,回到工作现场。
参考文章:Bug分支
Git Stash紧急处理问题,需要切分支的更多相关文章
- Git 分支管理-git stash 和git stash pop
https://blog.csdn.net/u010697394/article/details/56484492 合并分支,冲突是难免的,在实际协作开发中我们遇到的情况错综复杂,今天就讲两个比较重要 ...
- IDEA:Git stash 暂存分支修改的代码
IDEA:Git stash 暂存分支修改的代码 场景:当我们正在master分支开发新功能的时候,突然接到一个任务发现线上出现了一个紧急的BUG需要修复,由于没有打新分支做这部分新需求,这时正做到半 ...
- Git的Bug分支----临时保存现场git stash
软件开发中,bug就像家常便饭一样,有了bug就需要修复,在Git中,由于分支是如此的强大,所以每个bug通过一个新的分支来修复,在修复后,合并分支,然后将临时分支删除. 当你接到一个修复代号为119 ...
- Git如何在不提交当前分支的情况下切换到其它分支进行操作——git stash
假如现在的Bug你还没有解决,而上边又给你派了一个新的Bug,而这个Bug相比较现在正在苦思冥想的Bug比较容易解决. 你想先解决新的Bug,可是之前的Bug还没有解决完而不能提交.怎么办? 解决方法 ...
- git stash 切换分支以后 恢复
场景: 我在A分支开发 突然要去B分支改东西 但是A分支还没开发完 B又比较着急 又不想提交A 但是不提交又切换不到B 于是就发现有个git stash 将当前修改(未提交的代码)存入缓存区,切换分支 ...
- git stash封存分支 以及关于开发新功能的处理
有种情况,我们要修复项目的bug时,但别的分支有修改的代码,要修复的bug可能会影响(所有分支共用一个暂存区).可以单独创建一个bug分支,用于修复和提交bug,在修改前可以先stash封存分支修改的 ...
- git stash详解
应用场景: 1 当正在dev分支上开发某个项目,这时项目中出现一个bug,需要紧急修复,但是正在开发的内容只是完成一半,还不想提交,这时可以用git stash命令将修改的内容保存至堆栈区,然 ...
- git stash 存储命令
应用场景 一.当你接到一个修复紧急 bug 的任务时候,一般都是先创建一个新的 bug 分支来修复它,然后合并,最后删除.但是,如果当前你正在开发功能中,短时间还无法完成,无法直接提交到仓库,这时候可 ...
- Git stash方法(转)
命令:git stash1.使用git stash保存当前的工作现场,那么就可以切换到其他分支进行工作,或者在当前分支上完成其他紧急的工作,比如修订一个bug测试提交. 2.如果一个使用了一个git ...
随机推荐
- PhpStorm 相关激活方式
点击进入下面网站: http://idea.lanyus.com/
- 用批处理脚本一键安装 MongoDB
下载MongoDB安装文件,解压到D:\MongoDB: 运行脚本: @echo off set mongobin=D:\MongoDB ::在mongodb文件夹下建立data,log文件夹 md ...
- python 检查内存
################################# 测试函数运行内存# coding=utf-8# pip install memory_profiler# pip install p ...
- spring bean的生命周期
掌握好spring bean的生命周期,对spring的扩展大有帮助. spring bean的生命周期(推荐看) spring bean的生命周期
- Linux 文件系统分区基础
文件系统就是管理设备,组织文件的一些结构和算法. /boot分区,它包含了操作系统的内核和在启动系统过程中所要用到的文件, 建这个分 区是有必要的,因为目前大多数的PC机要受到BIOS的限制,况且如果 ...
- (转)浅谈Java中的equals和==
原文地址: http://www.cnblogs.com/dolphin0520/p/3592500.html 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new S ...
- linux下EOF写法梳理
在平时的运维工作中,我们经常会碰到这样一个场景:执行脚本的时候,需要往一个文件里自动输入N行内容.如果是少数的几行内容,还可以用echo追加方式,但如果是很多行,那么单纯用echo追加的方式就显得愚蠢 ...
- PAT 1043. 输出PATest(20)
给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按"PATestPATest...."这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一 ...
- [LeetCode] Interleaving String 交织相错的字符串
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 ...
- [LeetCode] Subsets 子集合
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...