在软件开发中,很多时候都会要求你停下手头的活去处理别的事情,那么,我们的代码写到一半,commit不了,怎么办呢?这个时候GIT会提供一个暂时储存的功能,是你的代码暂时放在安全的区域,等你的紧急任务,比如紧急Bug修复完成之后再来切回来继续手头的工作,具体代码如下:
$ git add . //现在在dev分支,代码添加文件到暂存区,但是没有commit
$ git stash //把代码暂存起来
$ git checkout master //切回主线
$ git checkout -b EmergencyIssue //创建分支修改EmergencyIssue
//After one hour...... EmergencyIssue fixed.
$ git checkout master //修改好之后切回主线
$ git merge --no-ff -m "merged bug fix EmergencyIssue" iEmergencyIssue //分支合并
$ git branch -d EmergencyIssue //删除分支
$ git checkout dev //切回dev的分支
$ git status //查看状态,但是发现什么都没有
$ git stash list //可以看到暂存区存起来的list
stash@{0}: WIP on dev: 888888 add merge
$ git stash pop //恢复stash后并删除stash的内容
$ git stash list 其实, git stash pop相当于下面两条命令:
$ git stash apply //恢复stash的内容
$ git stash drop //删除stash的内容
我们可以多次用git stash来把内容存起来,只要用git stash apply加上指定的stash就可以恢复了
$ git stash apply stash@{0} 本文内容来自:git创建分支,git合并分支,git分支管理以及git暂存区的使用 – Break易站
---Author: Arvin Chen ---Web Address: www.breakyizhan.com (Break易站)