秒懂Git分支的合并机制

简介: Basic Branching and Merging两种合并的情况:Fast-forward,merge-commit1. Fast-forward 快进when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together — thi

秒懂Git分支的合并机制



Basic Branching and Merging

两种合并的情况:Fast-forward,merge-commit

1. Fast-forward 快进


when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together — this is called a “fast-forward.”


如下:将hotfix分支合并到master分支上,只是将master分支上的指针向前移了一下。


$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
 index.html | 2 ++
 1 file changed, 2 insertions(+)


2020042319283920.png



2. merge commit 合并提交


Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it. This is referred to as a merge commit, and is special in that it has more than one parent


如下图:将iss53 分支合并到master分支,三方合并生成一个新的提交(合并提交)。


$ git checkout master
Switched to branch 'master'
$ git merge iss53
Merge made by the 'recursive' strategy.
index.html |    1 +
1 file changed, 1 insertion(+)


2020042319290466.png


注意:遇到冲突,要把冲突解决了,再手动 stage、commit

目录
相关文章
|
2月前
|
开发工具 git
Git教程:深入了解删除分支的命令
【4月更文挑战第3天】
381 0
Git教程:深入了解删除分支的命令
|
2月前
|
开发工具 git 开发者
|
1月前
|
项目管理 开发工具 git
Git项目管理——分支(三)
Git项目管理——分支(三)
24 2
|
25天前
|
开发工具 git 开发者
【git merge/rebase】详解合并代码、解决冲突
【git merge/rebase】详解合并代码、解决冲突
49 0
|
2月前
|
JSON 开发工具 git
git rebase 合并当前分支的多个commit记录
git rebase 合并当前分支的多个commit记录
|
2月前
|
开发工具 git 开发者
|
1月前
|
开发工具 git
git切换到另一分支更改也会随之过去
git切换到另一分支更改也会随之过去
22 1
|
1月前
|
开发工具 git
git将一个远程分支的部分修改提交到另一个远程分支
git将一个远程分支的部分修改提交到另一个远程分支
13 1
|
24天前
|
敏捷开发 测试技术 持续交付
【git分支管理策略】如何高效的管理好代码版本
【git分支管理策略】如何高效的管理好代码版本
55 0
|
2月前
|
开发工具 git
Git 保姆级教程(二):Git 分支
Git 保姆级教程(二):Git 分支