秒懂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

目录
相关文章
|
23天前
|
开发工具 git
Git教程:深入了解删除分支的命令
【4月更文挑战第3天】
43 0
Git教程:深入了解删除分支的命令
|
2月前
|
开发工具 git 开发者
|
2月前
|
开发工具 git
|
3月前
|
前端开发 算法 开发工具
Git分支批量清理利器:自定义命令行插件实战
Git分支批量清理利器:自定义命令行插件实战
47 0
|
3月前
|
开发工具 git
Git从远程仓库拉取指定的分支
Git从远程仓库拉取指定的分支
125 0
|
2月前
|
开发工具 git 开发者
|
2月前
|
开发工具 git
|
10天前
|
机器人 Java 测试技术
云效产品使用常见问题之流水线git自定义某一个分支提交节点失败如何解决
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
12天前
|
开发工具 git
git 拉取代码仓库代码报错(合并错误 refusing to merge unrelated histories)
git 拉取代码仓库代码报错(合并错误 refusing to merge unrelated histories)
20 0
|
22天前
|
开发工具 git
git如何创建新分支,GitHub默认分支是main怎么连上
git如何创建新分支,GitHub默认分支是main怎么连上
11 0

相关实验场景

更多