Git 实战(四)| Git 分支管理实操,搞定在线合并和本地合并

类似于 SVN 这种集中式版本管理,三年前刚来上海工作时候,在华为驻场上班,华为用的就是 SVN,印象最深的就是那个小乌龟的图标;后来到外面工作,渐渐发现用 Git 的非常多,慢慢学习了解发现 Git 这种分布式的版本管理确实很好很强大,后面也就重点学习 Git 的分支管理策略了(其实 SVN 我现在压根就不会了,哈哈。。。)

centralized workflows
以 Bitbucket 的官方文档的实例作为简单介绍:例如 Mary 现在想要开发,在开发前她可以通过 checkout 命令建立一个新的分支:

Feature Branch Workflow: comit changesBefore she starts developing a feature, Mary needs an isolated branch to work on. She can request a new branch with the following command
然后 Mary 可以在这个本地进行相关的更改:
接着她可以不断将本地修改上传至特性分支的中心仓库中,直到自己全完修改完成


然后,她在 git gui(GitHub 或 GitLab 等)中提交 pull 请求,请求将 marys 特性合并到 master 中,团队成员将自动收到通知。

Mary 的同事 Bill 收到了 pr,Bill 觉得在合并到正式项目中之前还需要做一些修改,于是在 pr 的回复中对 Mary 进行告知,接着 Mary 继续修改开发,完成后再次提交 pr:

一旦 Bill 准备接受 pull request,有人需要将该特征 merge 到稳定的项目中(这可以由 Bill 或 Mary 来完成)


在 GitHub 上进行基本的演示(实际工作中,公司用的还是 GitLab 较多,后面会有总结演示)1.1) 先使用 git checkout -b 命令来创建一个新的分支并切换到此分支中去,用 git branch 命令可查看当前所处分支:
1.2) 将 readme.txt 文件最后一行加入如下内容并 commit

1.3) push 到远程仓库并查看分支,首次 push 需要用 git push -u 或 git push --set-upstream 命令设置上下游的关联关系:

在 GitHub 上查看 master 分支和 gitTestBranch 分支的对比,可见 gitTestBranch 已成功 push:master:

gitTestBranch:

1.4) 使用 git log --graph --all --decorate=short 命令可以查看提交的分支走向,如果分支较多的话就会出现如下效果:

1.5)这个时候我们可以通过 pr 对分支进行 merge:发起 pr

没有 conflict,可以直接 merge

这个时候再看 master 分支,就已经被成功合并了

2.1) 先在 readme.txt 文件中加入一行 branch gitTestBranch update2,然后提交到远程分支中:

2.2)通过 fetch 将 gitTestBranch 分支拿下来到本地,修改本地文件并合并修改本地 gitTestBranch 分支,修改加入“branch gitTestBranch update3”并提交到远程分支
2.3)master 分支上 fetch 拿取远程 gitTestBranch 分支,修改冲突,合并提交
2.4)这时候在 GitHub 上进行查看:commit 历史中可见提交记录:

检查 master,发现已经被成功合并

免费领取:性能测试+接口测试+自动化测试+测试开发+测试用例+简历模板+测试文档
http://qrcode.testing-studio.com/f?from=infoQ&url=https://ceshiren.com/t/topic/16565
评论