何时在Git中使用'--no-ff'合并选项 [英] When to use the '--no-ff' merge option in Git

查看:1077
本文介绍了何时在Git中使用'--no-ff'合并选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个成功的Git分支模型建议使用 - no-ff 合并分支时:


- no-ff 标志导致合并总是创建一个新的提交
对象,即使合并可以用快进执行。这
避免丢失关于一个功能
分支的历史存在的信息,并将所有提交一起加上
功能。 [b]

是的,它会创建更多(空)提交对象,但获得的收益是
要大得多。不幸的是,我还没有找到一种方法来
- no-ff git合并的默认行为,但它确实是
应该是。


了解Git工作流程,但是,建议不要使用 - no-ff


所以你添加一个新的规则:当你在你的功能分支中合并时,使用
- no-ff 来强制一个新提交。这样做可以完成工作,并且可以移动
。 [b]
$ b

- no-ff band-aid,broken bisect 责备 奥秘都是
您将螺丝刀用作锤子的症状。 [b]

这两种方法对于不同的情况似乎都合理,但是什么被认为是良好做法?



你什么时候使用 - no-ff ,为什么?

解决方案

这确实取决于你想要做什么。我的经验法则是,如果合并意味着什么,我使用--no-ff选项。当合并并不意味着什么,你可能使用了rebase,没有理由使用--no-ff



git的一个特点是它非常强大的工具,你可以用很多方式使用它 - 其中大部分都没有错。问什么是正确的方法,就像问问什么是正确的绘画方式。



至少对我来说,这是一种不断演变的方式,我喜欢做到这一点,我们经常在团队中讨论我们如何在代码上进行协作 - 从中​​我们试图推导出一种如何在这里完成的标准,但这只是我们的做法。


A Successful Git Branching Model recommends to use --no-ff when merging branches:

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. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature. […]

Yes, it will create a few more (empty) commit objects, but the gain is much bigger that that cost. Unfortunately, I have not found a way to make --no-ff the default behavior of git merge yet, but it really should be.

Understanding the Git Workflow, however, recommends not to use --no-ff:

So you add a new rule: "When you merge in your feature branch, use –-no-ff to force a new commit." This gets the job done, and you move on. […]

The --no-ff band-aid, broken bisect, and blame mysteries are all symptoms that you’re using a screwdriver as a hammer. […]

Both approaches seem reasonable for difference scenarios, but what is considered "good practice?"

When do you use --no-ff, when do you not, why?

解决方案

It's really dependent on what you're trying to do. My rule of thumb is that if the merge "means something" I use the --no-ff option. When the merge doesn't really mean anything and you might have used a rebase there's no reason to use --no-ff

The thing with git is that it's a very powerful tool, and you can use it in many ways - most of which are not wrong. Asking what's the "right way" to do it is like asking what's the right way to paint a picture.

At least for me it's an evolving set of ways I like to do it, with frequent discussions in the team of how we want to collaborate on the code - from this we try to derive a kind of "how it's done here" standard, but it's just our way of doing it.

这篇关于何时在Git中使用'--no-ff'合并选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆