git分支管理策略
来源:互联网 发布:韩国拍照软件 编辑:程序博客网 时间:2024/06/05 23:54
通常,合并分支时,如果可能,Git会用Fast forward
模式,但这种模式下,删除分支后,会丢掉分支信息。
如果要强制禁用Fast forward
模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。
下面我们实战一下--no-ff
方式的git merge
:
首先,仍然创建并切换dev
分支:
$ git checkout -b devSwitched to a new branch 'dev'
修改readme.txt文件,并提交一个新的commit:
$ git add readme.txt $ git commit -m "add merge"[dev 6224937] add merge 1 file changed, 1 insertion(+)
现在,我们切换回master
:
$ git checkout masterSwitched to branch 'master'
准备合并dev
分支,请注意--no-ff
参数,表示禁用Fast forward
:
$ git merge --no-ff -m "merge with no-ff" devMerge made by the 'recursive' strategy. readme.txt | 1 + 1 file changed, 1 insertion(+)
因为本次合并要创建一个新的commit,所以加上-m
参数,把commit描述写进去。
合并后,我们用git log
看看分支历史:
$ git log --graph --pretty=oneline --abbrev-commit* 7825a50 merge with no-ff|\| * 6224937 add merge|/* 59bc1cb conflict fixed...
可以看到,不使用Fast forward
模式,merge后就像这样:
分支策略
在实际开发中,我们应该按照几个基本原则进行分支管理:
首先,master
分支应该是非常稳定的,也就是仅用来发布新版本,平时不能在上面干活;
那在哪干活呢?干活都在dev
分支上,也就是说,dev
分支是不稳定的,到某个时候,比如1.0版本发布时,再把dev
分支合并到master
上,在master
分支发布1.0版本;
你和你的小伙伴们每个人都在dev
分支上干活,每个人都有自己的分支,时不时地往dev
分支上合并就可以了。
所以,团队合作的分支看起来就像这样:
小结
Git分支十分强大,在团队开发中应该充分应用。
合并分支时,加上--no-ff
参数就可以用普通模式合并,即重新做了一次commit,合并后的历史有分支,具体可以从Log里面查看,能看出来曾经做过合并,并能够很容易的做版本回退。而fast forward
合并只是将指针移动到合并后的分支,log里卖弄没有记录。就看不出来曾经做过合并。
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git 分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git分支管理策略
- Git 分支管理策略
- Git分支管理策略
- 【Excel】java 导出Excel 中文文件名乱码不显示问题
- 第四周项目3-单链表应用(3)
- error LNK2005: ___xc_a already defined in msvcrt.lib(cinitexe.obj)
- 309. Best Time to Buy and Sell Stock with Cooldown
- 第四周 单链表的应用(3)
- git分支管理策略
- 微信小应用开发工具 共享共享共享啦
- Android 创建简单菜单 memu
- Bubble Cup 9 - Finals [Online Mirror] 题解
- Windbg调试32位.net程序产生的64位dump
- php识别移动端代码
- Set说明
- NVIDIA PhysX SDK 3.3.4 Documentation User's Guide翻译 --Vehicles
- linux环境内存分配原理 mallocinfo