本文翻译自:What is the difference between `git merge` and `git merge --no-ff`?

Using gitk log , I could not spot a difference between the two. 使用gitk log ,我无法发现两者之间的差异。 How can I observe the difference (with a git command or some tool)? 如何观察差异(使用git命令或某些工具)?


#1楼

参考:https://stackoom.com/question/c3HB/git-merge和git-merge-no-ff有什么区别


#2楼

Graphic answer to this question 这个问题的图形答案

Here is a site with a clear explanation and graphical illustration of using git merge --no-ff : 这是一个使用git merge --no-ff的清晰解释和图形说明的站点 :

Until I saw this, I was completely lost with git. 直到我看到这个,我对git完全迷失了。 Using --no-ff allows someone reviewing history to clearly see the branch you checked out to work on. 使用--no-ff可以使查看历史记录的人清楚地看到您签出的分支以进行工作。 (that link points to github's "network" visualization tool) And here is another great reference with illustrations. (该链接指向github的“网络”可视化工具),这是另一个带有插图的出色参考 。 This reference complements the first one nicely with more of a focus on those less acquainted with git. 该参考文献很好地补充了第一个参考文献,更多地侧重于那些不熟悉git的读者。


Basic info for newbs like me 像我这样的新手的基本信息

If you are like me, and not a Git-guru, my answer here describes handling the deletion of files from git's tracking without deleting them from the local filesystem, which seems poorly documented but often occurrence. 如果您像我一样,而不是Git-guru,那么我在这里的答案描述了如何处理git跟踪中的文件删除操作,而不是从本地文件系统中删除文件,这似乎文献记载不多,但经常发生。 Another newb situation is getting current code , which still manages to elude me. 另一个新情况是获取当前代码 ,但仍然设法使我难以理解。


Example Workflow 工作流程示例

I updated a package to my website and had to go back to my notes to see my workflow; 我将软件包更新到了​​我的网站,不得不回到笔记中才能看到我的工作流程; I thought it useful to add an example to this answer. 我认为向该答案添加示例非常有用。

My workflow of git commands: 我的git命令工作流程:

git checkout -b contact-form
(do your work on "contact-form")
git status
git commit -am  "updated form in contact module"
git checkout master
git merge --no-ff contact-form
git branch -d contact-form
git push origin master

Below: actual usage, including explanations. 下图:实际用法,包括说明。
Note: the output below is snipped; 注意:以下输出被截断; git is quite verbose. git非常冗长。

$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   ecc/Desktop.php
#       modified:   ecc/Mobile.php
#       deleted:    ecc/ecc-config.php
#       modified:   ecc/readme.txt
#       modified:   ecc/test.php
#       deleted:    passthru-adapter.igs
#       deleted:    shop/mickey/index.php
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ecc/upgrade.php
#       ecc/webgility-config.php
#       ecc/webgility-config.php.bak
#       ecc/webgility-magento.php

Notice 3 things from above: 注意上面的三件事:
1) In the output you can see the changes from the ECC package's upgrade, including the addition of new files. 1)在输出中,您可以看到ECC软件包升级后的更改,包括添加新文件。
2) Also notice there are two files (not in the /ecc folder) I deleted independent of this change. 2)还要注意,我删除了两个文件(不在/ecc文件夹中),与此更改无关。 Instead of confusing those file deletions with ecc , I'll make a different cleanup branch later to reflect those files' deletion. ecc将这些文件删除与ecc混淆,我稍后将创建一个不同的cleanup分支以反映这些文件的删除。
3) I didn't follow my workflow! 3)我没有遵循我的工作流程! I forgot about git while I was trying to get ecc working again. 我在尝试再次使ecc工作时忘记了git。

Below: rather than do the all-inclusive git commit -am "updated ecc package" I normally would, I only wanted to add the files in the /ecc folder. 下图:我通常不会将包罗万象的git commit -am "updated ecc package" ,而是只想将文件添加到/ecc文件夹中。 Those deleted files weren't specifically part of my git add , but because they already were tracked in git, I need to remove them from this branch's commit: 这些删除的文件不是我git add一部分,但是由于已经在git中对其进行了跟踪,因此我需要从该分支的提交中删除它们:

$ git checkout -b ecc
$ git add ecc/*
$ git reset HEAD passthru-adapter.igs
$ git reset HEAD shop/mickey/index.php
Unstaged changes after reset:
M       passthru-adapter.igs
M       shop/mickey/index.php$ git commit -m "Webgility ecc desktop connector files; integrates with Quickbooks"$ git checkout master
D       passthru-adapter.igs
D       shop/mickey/index.php
Switched to branch 'master'
$ git merge --no-ff ecc
$ git branch -d ecc
Deleted branch ecc (was 98269a2).
$ git push origin master
Counting objects: 22, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (14/14), 59.00 KiB, done.
Total 14 (delta 10), reused 0 (delta 0)
To git@github.com:me/mywebsite.git8a0d9ec..333eff5  master -> master

Script for automating the above 自动化上述脚本

Having used this process 10+ times in a day, I have taken to writing batch scripts to execute the commands, so I made an almost-proper git_update.sh <branch> <"commit message"> script for doing the above steps. 在一天中使用此过程十次以上之后,我开始编写批处理脚本来执行命令,因此我制作了几乎正确的git_update.sh <branch> <"commit message">脚本来完成上述步骤。 Here is the Gist source for that script. 这是该脚本的要点源 。

Instead of git commit -am I am selecting files from the "modified" list produced via git status and then pasting those in this script. 我不是从git commit -am而是从通过git status生成的“已修改”列表中选择文件,然后将其粘贴到此脚本中。 This came about because I made dozens of edits but wanted varied branch names to help group the changes. 发生这种情况是因为我进行了数十次编辑,但希望使用不同的分支名称来帮助对更改进行分组。


#3楼

The --no-ff option ensures that a fast forward merge will not happen, and that a new commit object will always be created . --no-ff选项确保不会发生快速向前合并,并且始终会创建一个新的提交对象 。 This can be desirable if you want git to maintain a history of feature branches. 如果您希望git维护功能分支的历史记录,则可能需要这样做。 In the above image, the left side is an example of the git history after using git merge --no-ff and the right side is an example of using git merge where an ff merge was possible. 在上图中,左侧是使用git merge --no-ff之后的git历史的示例,右侧是使用ff merge可以使用git merge的示例。

EDIT : A previous version of this image indicated only a single parent for the merge commit. 编辑 :此图像的先前版本仅指示合并提交的单亲。 Merge commits have multiple parent commits which git uses to maintain a history of the "feature branch" and of the original branch. 合并提交有多个父提交 ,git用来维护“功能分支”和原始分支的历史记录。 The multiple parent links are highlighted in green. 多个父链接以绿色突出显示。


#4楼

这是一个古老的问题,在其他帖子中也对此进行了微妙的提及,但对我而言,单击此按钮的原因是, 非快进合并将需要单独的commit


#5楼

Merge Strategies 合并策略

Explicit Merge : Creates a new merge commit. 显式合并 :创建一个新的合并提交。 (This is what you will get if you used --no-ff .) (如果使用--no-ff这将是您得到的。)

Fast Forward Merge: Forward rapidly, without creating a new commit: 快速转发合并:快速转发 ,而无需创建新的提交:

Rebase : Establish a new base level: 重新设定 :建立新的基本等级:

Squash: Crush or squeeze (something) with force so that it becomes flat: 壁球:挤压或挤(东西)与力,使其变得平坦:


#6楼

The --no-ff flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. --no-ff标志使合并始终创建一个新的提交对象,即使合并可以通过快进来执行。 This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature 这样可以避免丢失有关要素分支历史存在的信息,并将所有添加了要素的提交分组在一起

git merge和git merge --no-ff有什么区别?相关推荐

  1. git:Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists)....

    Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists). 解决办法一:保 ...

  2. git merge 和 git rebase详解

    git merge 和 git rebase 都是用来合并两个分支的. git merge b   #把b分支合并到当前分支 git rebase b   #把b分支合并到当前分支 --------- ...

  3. Git分支合并:Merge、Rebase的选择

    git代码合并:Merge.Rebase的选择 - iTech - 博客园 http://www.cnblogs.com/itech/p/5188932.html Git如何将一个分支的修改同步到另一 ...

  4. git rebase和git merge的用法

    http://softlab.sdut.edu.cn/blog/subaochen/2016/01/git-rebase%E5%92%8Cgit-merge%E7%9A%84%E7%94%A8%E6% ...

  5. Git笔记(三)——[cherry-pick, merge, rebase]

    书接上回,直入主题!这篇继续实践剩下的几个命令. 现在的SourceTree状态如下: cherry-pick - 妈妈,我也要 cherry-pick其实在工作中还挺常用的,一种常见的场景就是,比如 ...

  6. Git rebase 和 Git merge 的区别,你知道吗?

    编辑搜图 请点击输入图片描述 Git是大多数程序必备的工具之一,Git常用那么几个命令:pull.push.status.merge.rebase.Git rebase 和 Git merge都是合并 ...

  7. Git 学习笔记之 merge

    Merge: 1.Fast-forward(快进式) 2.recursice strategy (策略合并,三方合并) Fast-forward 策略合并 //创建一个文件夹,并初始化 Git mkd ...

  8. git 的 merge 与 no-ff merge 的不同之处

    文章目录 参考链接 证明 参考链接 分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息.如果要强制禁用Fast forward模 ...

  9. git常用命令+git规范(附merge合并及冲突解决)

    一.VCS版本控制系统 version control system(VCS),用于项目中存储.共享.合并.历史回退.代码追踪文件历史等功能. VCS软件: 2000年以前 2010年以前 2010年 ...

最新文章

  1. I2C原理及特性总结
  2. mysql单列索引和多列索引_浅谈MySQL索引优化
  3. 618 兵临城下,你需要一个更省钱省力的数据根基平台!
  4. 每日一笑 | 各大互联网公司离职员工群名
  5. 一拍即合、一见钟情之后,智慧城市的“福利”来啦……
  6. 如何成为一名卓越的数据科学家——开篇七剑
  7. Microsoft漏洞补丁包下载地址大全
  8. input标签详解,用户注册表单
  9. 学习方法——哈佛大学幸福课(积极心理学)学习笔记(上)
  10. 缤纷彩色文字广告代码,文字广告代码美化版,给网站添加文字广告教程
  11. usb线连接android设备连接不上,安卓手机USB数据线连接不上电脑怎么办
  12. java float 大小比较_java浮点型比较大小
  13. C++入门基础(上)
  14. 【第86期】CPU 空闲时在干嘛?
  15. 《微积分:一元函数微分学》——狄利克雷函数
  16. centOS关机重启,保存内存中数据
  17. Python入门实例验证及结果之实例7 圆周率的计算 ##程序循环结构 ##random库
  18. 官宣!香港大学,将落户深圳
  19. accessible: module java.base does not “opens java.lang“ to unnamed module
  20. 混合正交表生成工具——allpairs安装及使用

热门文章

  1. R-Sys.time计算程序运行时间
  2. hsrp+route-map 解决多路由器多isp
  3. 关于java mail 发邮件的问题总结(转)
  4. Trim or Discard or Unmap
  5. HttpClient 模拟登录网易微博
  6. 如何想要在开机启动登陆时,用户名也不输入
  7. Oracle数据库重复数据删除的三种情况
  8. 命中书中题有奖反馈活动_三级网络技术
  9. 企业内部IT报修是如何操作的?
  10. Ubuntu下如何修改文件或者文件夹的权限