小浣熊做单网站,韩国风格网站模板,摄影工作室网站模板,国外 设计 网站前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。
合并分支#xff0c;冲突是难免的#xff0c;在实际协作开发中我们遇到的情况错综复杂#xff0c;今天就讲两个比较重要的命令使用gi…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。
合并分支冲突是难免的在实际协作开发中我们遇到的情况错综复杂今天就讲两个比较重要的命令使用git stash 和git stash pop
试想一下1.假如我们在develop分支开发这时候突然技术经理说有个紧急修复下这修复bug之前说了需要从master稳定版本开一个分支而我们develop如果没有commit而直接切换到master会有如下提示 [plain] view plain copy zxdeMacBook-Pro:hswallpager zs$ git checkout master error: Your local changes to the following files would be overwritten by checkout: app/src/main/java/Activity.java Please, commit your changes or stash them before you can switch branches. Aborting zxdeMacBook-Pro:hswallpager zs$ git branch * develop master 根据提示我们需要提交修改或者在切换分之前 stash 一下。而我们每次间断就要commit一次将来git log里会有很多临时提交太多了让人无法快速定位而这的确不是我们想要的那就只有stash。stash的含义就是把工作区的修改临时储藏起来等以后再恢复使用。那我们不妨一试git stash看看结局是什么样子的 [plain] view plain copy zxdeMacBook-Pro:hswallpager zs$ git stash Saved working directory and index state WIP on develop: b70f2af develop update HEAD is now at b70f2af develop update 先看最后一句 HEAD is now at b70f2af develop update. 还记得上一篇的分支图吧。 [plain] view plain copy * 073fc5c 合并后的修改 |\ | * b70f2af develop update * | 41754e3 修改 |/ 因为我们上一篇master合并后develop后并没有将develop的分支和master同步因此develop分支的最新的提交记录就在b70f2af也就是工作区目前是干净的。git stash 执行后develop分支就相当于什么也没操作一样。 接着我们在执行最开始的切换到master分支看看会怎样还会不会提示上述信息 [plain] view plain copy zxdeMacBook-Pro:hswallpager zs$ git checkout master Switched to branch master Your branch is ahead of origin/master by 8 commits. (use git push to publish your local commits) zxdeMacBook-Pro:hswallpager zs$ git branch develop * master 怎么样是不是正确切换到master分支了。现在我们在新建并切换分支hotfixes-01.然后可以修复紧急bug了。然后修改提交删除hotfixes-01即可。然后我们继续切回develop分支 [plain] view plain copy zxdeMacBook-Pro:hswallpager zs$ git checkout develop Switched to branch develop zxdeMacBook-Pro:hswallpager zs$ git status On branch develop nothing to commit, working directory clean 这时候我们可以先把master分支的修改合并到develop操作步骤以前也学过了合并冲突等。这时候我们看会代码stash之前的代码已经看不到了。那我们怎么继续接着上述的修改恢复现场呢。这时候用到git stash pop。我们先看一下stash清单执行git stash list。 [plain] view plain copy zxdeMacBook-Pro:hswallpager zs$ git stash list stash{0}: WIP on develop: b70f2af develop update 然后我们用git stash pop 恢复现场看一下结果 [plain] view plain copy zxdeMacBook-Pro:hswallpager zs$ git stash pop On branch develop 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: app/src/main/java/Activity.java no changes added to commit (use git add and/or git commit -a) Dropped refs/stash{0} (44c79bddb5c6c3848bc0de0b687cf14d4907b012) 这时候在看工作区的源代码发现已经正确恢复现场可以继续在以前基础上工作了。 2.现在另一种情况你pull最新代码但这时候你又不想重新增加commit记录这时候先git stash然后pull最后在git stash pop, 这1和2两种情况在实际开发过程中会经常用到要熟练掌握git stash的应用。
补充在我们多次使用git stash 后git栈里充满了很多未提交的代码这时候用git stash list 可以讲git 栈信息打印出来比如
git stash apply stash{1} 就代表把指定版本号为stash{1}的工作取出来。清空的话使用git stash clear。 git stash pop 和 git stash apply 的不同
apply 读取暂存区的数据通过apply后暂存区的数据依然存在。
pop 是取出最新的一次暂存数据pop后暂存区就不会存在这次数据了。 总结
git stash #可用来暂存当前正在进行中的工作
git stash pop #从git栈中恢复第一个。相当于git stash apply 和git stash drop
git stash list #打印git栈中的所有信息
git stash clear #清空git栈
git stash apply stash{1} #将你指定版本号为stash{1}的工作取出 版本分支是git区分集中式版本控制的一大优势而为了保证团队协作中顺利的开发建议大家多用分支至于具体分支的命名不必拘泥死板根据自己团队的实际情况让分支成为我们团队开发的助推器而不是拖后腿。