邢台网站建设包括哪些,合肥网站建设的公司,网页制作0基础怎么学,大型旅游网站源码 织梦 2016软件开发中#xff0c;bug就像家常便饭一样。有了bug就需要修复#xff0c;在Git中#xff0c;由于分支是如此的强大#xff0c;所以#xff0c;每个bug都可以通过一个新的临时分支来修复#xff0c;修复后#xff0c;合并分支#xff0c;然后将临时分支删除。
当你接…软件开发中bug就像家常便饭一样。有了bug就需要修复在Git中由于分支是如此的强大所以每个bug都可以通过一个新的临时分支来修复修复后合并分支然后将临时分支删除。
当你接到一个修复一个代号101的bug的任务时很自然地你想创建一个分支issue-101来修复它但是等等当前正在dev上进行的工作还没有提交
$ git status
On branch dev
Changes to be committed:(use git reset HEAD file... to unstage)new file: hello.pyChanges 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: readme.txt并不是你不想提交而是工作只进行到一半还没法提交预计完成还需1天时间。但是必须在两个小时内修复该bug怎么办
幸好Git还提供了一个stash功能可以把当前工作现场“储藏”起来等以后恢复现场后继续工作
$ git stash
Saved working directory and index state WIP on dev: f52c633 add merge现在用git status查看工作区就是干净的除非有没有被Git管理的文件因此可以放心地创建分支来修复bug。
首先确定要在哪个分支上修复bug假定需要在master分支上修复就从master创建临时分支
$ git checkout master
Switched to branch master
Your branch is ahead of origin/master by 6 commits.(use git push to publish your local commits)$ git checkout -b issue-101
Switched to a new branch issue-101现在修复bug需要把“Git is free software …”改为“Git is a free software …”然后提交
$ git add readme.txt
$ git commit -m fix bug 101
[issue-101 4c805e2] fix bug 1011 file changed, 1 insertion(), 1 deletion(-)修复完成后切换到master分支并完成合并最后删除issue-101分支
$ git checkout master
Switched to branch master
Your branch is ahead of origin/master by 6 commits.(use git push to publish your local commits)$ git merge --no-ff -m merged bug fix 101 issue-101
Merge made by the recursive strategy.readme.txt | 2 -1 file changed, 1 insertion(), 1 deletion(-)太棒了原计划两个小时的bug修复只花了5分钟现在是时候接着回到dev分支干活了
$ git checkout dev
Switched to branch dev$ git status
On branch dev
nothing to commit, working tree clean工作区是干净的刚才的工作现场存到哪去了用git stash list命令看看
$ git stash list
stash{0}: WIP on dev: f52c633 add merge工作现场还在Git把stash内容存在某个地方了但是需要恢复一下有两个办法
一是用git stash apply恢复但是恢复后stash内容并不删除你需要用git stash drop来删除
另一种方式是用git stash pop恢复的同时把stash内容也删了
$ git stash pop
On branch dev
Changes to be committed:(use git reset HEAD file... to unstage)new file: hello.pyChanges 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: readme.txtDropped refs/stash{0} (5d677e2ee266f39ea296182fb2354265b91b3b2a)再用git stash list查看就看不到任何stash内容了
$ git stash list你可以多次stash恢复的时候先用git stash list查看然后恢复指定的stash用命令
$ git stash apply stash{0}小结 修复bug时我们会通过创建新的bug分支进行修复然后合并最后删除
当手头工作没有完成时先把工作现场git stash一下然后去修复bug修复后再git stash pop回到工作现场。