A Successful Git Branching Model建议 merge 分支时使用--no-ff
:
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但是,建议不要使用--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, brokenbisect
, andblame
mysteries are all symptoms that you’re using a screwdriver as a hammer. […]
对于不同的场景,这两种方法似乎都是合理的,但什么是“良好实践”?
什么时候用--no-ff
,什么时候不用,为什么?
最佳答案
这真的取决于你想做什么。我的经验是,如果 merge “有意义”,我会使用 --no-ff
选项。当 merge 实际上没有任何意义并且您可能使用了 rebase 时,没有理由使用 --no-ff
。
git 的优点在于它是一个非常强大的工具,您可以通过多种方式使用它——其中大部分都没有错。问什么是“正确的方法”,就像问什么是正确的绘画方法。
至少对我来说,这是我喜欢的一套不断发展的方式,团队中经常讨论我们希望如何在代码上进行协作——我们试图从中得出一种“这里是如何完成的”标准,但这只是我们的做法。
关于git - 何时在 Git 中使用 '--no-ff' merge 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18126297/