Git -> git merge --no-ff 和 git merge的区别

git merge --no-ff <branch>git merge <branch> 的区别

核心区别

git merge <branch>:

  • 默认使用Fast-forward模式(若可行)
  • 不创建额外的合并提交记录
  • 合并后看不出曾经存在过分支
    git merge --no-ff <branch>:
  • 强制创建一个新的合并提交
  • 即使可以Fast-forward也会生成合并记录
  • 保留完整的分支历史信息

合并前 (两种方式相同的初始状态)

bash 复制代码
     A---B---C (master)
         \
          D---E (branch)

Fast-forward模式合并后 (git merge)

bash 复制代码
 A---B---C---D---E (master)

No Fast-forward模式合并后 (git merge --no-ff)

bash 复制代码
 A---B---C-------M (master)
     \           /
      D---------E

选择建议: 临时分支用默认模式,重要功能分支用--no-ff以保留历史。

注:图中A、B、C、D、E分别代表不同的提交。B是从A创建分支的共同起点,而不是BD是同一笔提交。

相关推荐
wdfk_prog1 天前
实战教程:从“对象文件为空“到仓库重生——修复 Git 仓库损坏全记录
大数据·网络·笔记·git·学习·elasticsearch·全文检索
ALex_zry1 天前
Git Status 命令深度指南:洞悉仓库状态的核心艺术
大数据·git·elasticsearch
啃火龙果的兔子1 天前
如何在 VS Code 中进行 `cherry-pick`
git
夜里慢慢行4561 天前
git工程多个remote 拉取推送
git
啃火龙果的兔子2 天前
Git `cherry-pick` 工具汇总
git
ALex_zry2 天前
Git 乱码文件处理全流程指南:从识别到彻底清除
git·elasticsearch·搜索引擎
李梦晓2 天前
git 提交代码到别的分支
前端·git
思绪漂移2 天前
更改CodeBuddy的默认terminal为Git Bash
git·bash·terminal·codebuddy
一世暖阳7932 天前
git创建独立分支并上传远程仓库
git
《小书生》2 天前
git stash 暂存文档
git