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

网友投稿 469 2022-05-30

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

centralized workflows

以Bitbucket的官方文档的实例作为简单介绍:

例如Mary现在想要开发,在开发前她可以通过checkout命令建立一个新的分支:

Feature Branch Workflow: comit changes

Before she starts developing a feature, Mary needs an isolated branch to work on. She can request a new branch with the following command

git checkout -b marys-feature master

然后Mary可以在这个本地进行相关的更改:

git status git add git commit

接着她可以不断将本地修改上传至特性分支的中心仓库中,直到自己全完修改完成

git push -u origin marys-feature

git push

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

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

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

git checkout master git pull git pull origin marys-feature git push

在GitHub上进行基本的演示(实际工作中,公司用的还是GitLab较多,后面会有总结演示)

1.1) 先使用git checkout -b命令来创建一个新的分支并切换到此分支中去,用git branch命令可查看当前所处分支:

$ git checkout -b gitTestBranch Switched to a new branch 'gitTestBranch' $ git branch * gitTestBranch master

1.2) 将readme.txt文件最后一行加入如下内容并commit

I am a test engineer. I want to study Git. branch gitTestBranch update

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,然后提交到远程分支中:

I am a test engineer. I want to study Git. branch gitTestBranch update1 branch gitTestBranch update2

git commit -a -m "gitTestBranch second update" git push

2.2)通过fetch将gitTestBranch分支拿下来到本地,修改本地文件并合并

修改本地gitTestBranch分支,修改加入“branch gitTestBranch update3”并提交到远程分支

vi readme.txt I am a test engineer. I want to study Git. branch gitTestBranch update1 branch gitTestBranch update2 branch gitTestBranch update3 $ git commit -a -m "third update" $ git push

2.3)master分支上fetch拿取远程gitTestBranch分支,修改冲突,合并提交

$ git checkout master $ git fetch origin gitTestBranch $ git merge origin/gitTestBranch # fix conflict $ git commit -a -m "fix conflict" $ git push

2.4)这时候在GitHub上进行查看:

commit历史中可见提交记录:

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

参考链接:

git的基本使用流程

https://www.atlassian.com/git/tutorials/setting-up-a-repository

特性分支工作流

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

https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow

gitlab工作流

https://docs.gitlab.com/ee/workflow/gitlab_flow.html

多种工作流对比

https://www.atlassian.com/git/tutorials/comparing-workflows

gitlab私服搭建

https://docs.gitlab.com/omnibus/docker/

Git

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java中wait和notify的虚假唤醒问题
下一篇:前端 vue 在可视化大屏领域的工作实践
相关文章