Iva*_*lov 257
--no-ff当您想要明确概念功能分支时,该选项很有用.因此,即使在此期间没有提交任何提交,FF也是可能的 - 您仍然希望有时让主线中的每个提交对应一个功能.因此,您将具有一堆提交的功能分支视为一个单元,并将它们合并为一个单元.从您的历史中可以清楚地看到,当您使用分支合并功能时--no-ff.
如果你不关心这样的事情 - 你可能会尽可能地逃脱FF.因此,您将拥有更多类似svn的工作流感.
例如,这个笔者文章认为,--no-ff选项应该是默认的,他的理由是接近我上面列出:
考虑一下"功能"分支上的一系列次要提交共同构成一个新功能的情况:如果你只是执行"git merge feature_branch" --no-ff,"就不可能从Git历史中看到哪些提交对象一起拥有实现了一个功能 - 您必须手动读取所有日志消息.恢复整个功能(即一组提交),真是令人头痛[如果--no-ff没有使用],而如果使用该--no-ff标志则很容易完成[因为这只是一次提交."
当我们在开发环境中工作并将我们的代码合并到暂存/生产分支时,Git no fast forward 可能是更好的选择。通常,当我们在开发分支中为单个功能工作时,我们往往会进行多次提交。以后跟踪多个提交的更改可能会很不方便。如果我们使用 Git 与暂存/生产分支合并,没有快进,那么它将只有 1 次提交。现在,无论何时我们想要还原该功能,只需还原该提交即可。生活很容易。
我可以举一个在项目中很常见的例子。
在这里,选项--no-ff(即true merge)创建了一个具有多个父对象的新提交,并提供了更好的历史记录跟踪。否则,默认情况下--ff(即快速合并)。
$ git checkout master
$ git checkout -b newFeature
$ ...
$ git commit -m 'work from day 1'
$ ...
$ git commit -m 'work from day 2'
$ ...
$ git commit -m 'finish the feature'
$ git checkout master
$ git merge --no-ff newFeature -m 'add new feature'
$ git log
// something like below
commit 'add new feature' // => commit created at merge with proper message
commit 'finish the feature'
commit 'work from day 2'
commit 'work from day 1'
$ gitk // => see details with graph
$ git checkout -b anotherFeature // => create a new branch (*)
$ ...
$ git commit -m 'work from day 3'
$ ...
$ git commit -m 'work from day 4'
$ ...
$ git commit -m 'finish another feature'
$ git checkout master
$ git merge anotherFeature // --ff is by default, message will be ignored
$ git log
// something like below
commit 'work from day 4'
commit 'work from day 3'
commit 'add new feature'
commit 'finish the feature'
commit ...
$ gitk // => see details with graph
Run Code Online (Sandbox Code Playgroud)
(*)注意,在这里如果newFeature分支被重用,而不是创建一个新分支,git仍然必须进行--no-ff合并。这意味着快速前进合并并不总是符合条件。