仅在将外部分支合并到master中时才阻止快速合并

仅在将外部分支合并到master中时才阻止快速合并

本文介绍了Git:仅在将外部分支合并到master中时才阻止快速合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了便于查看要素分支何时合并到母版,将要素分支合并到母版时可以使用Git的--no-ff选项.

无需输入--no-ff即可完成此操作的一种方法是完全禁用快进合并到master中:

git config branch.master.mergeoptions --no-ff

但是,这很笨拙,因为当简单地将master的上游更改合并到master的本地副本(合并提交是为普通的git pull创建的)时,它还阻止了快进合并.

是否有某种方法可以配置Git,以仅在将功能分支合并到主服务器中时阻止快速转发合并到主服务器中,以便在从主服务器执行git pull时允许快速转发,但是合并要素分支时总是创建合并提交吗?还是明确地使用--no-ff来完成此任务的唯一方法?

解决方案

注意:预合并钩子不存在.
它于2008年推出,并且然后被批评(因为该控件最好在服务器上实现(使用更新挂钩).
它正在重新引入过程中( 2012年9月)

提交前/提交后钩子不存在不能在git merge 完成的自动提交上运行.

所以:

  • 您要么在开发人员正在推送的git服务器上放置了一个更新钩子(但是到那时,对于他们而言,意识到实现快速前进的功能分支可能为时已晚)
  • 或者您编写(以及分发和维护...)一个git-merge包装器,该包装器将在本地存储库级别执行该控制.
就像我在"",使用--no-ff具有其优势,因为它不会破坏git bisectgit blame .
因此,某个功能的开发人员可能希望在主分支中快进之前重新组织他/她的功能提交(如果数量太多,将它们压缩一点)(而不是创建一个巨大的提交) ).
有关更多信息,请参见"了解Git工作流程".

In order to make it easy to see when feature branches are merged to master, one can use Git's --no-ff option when merging their feature branch into master.

One way to accomplish this without needing to type --no-ff is to disable fast-forward merges into master entirely:

git config branch.master.mergeoptions --no-ff

However, this is clumsy since it also prevents fast-forward merges when simply merging upstream changes in master to a local copy of master (merge commits are created for normal git pulls.)

Is there some way to configure Git to prevent fast-forward merges into master only when merging feature branches into master, so that fast-forwards are allowed when doing git pulls from master, but merge commits are always created when merging feature branches? Or is explicitly using --no-ff the only way to accomplish this?

解决方案

Note: a pre-merge hook doesn't exist.
It was introduced in 2008, and criticized then (because the controlhad better be implemented on the server (using an update hook).
It is in the process of being re-introduced (September 2012)

And a pre/post-commit hook isn't run on the auto-commit done by a git merge.

So:

  • either you put in place an update hook on a git server where developers are pushing (but that may be too late by then for them to realize they fast-forwarded a feature branch)
  • or you write (and distribute, and maintain...) a git-merge wrapper which will do that control at the local repo level.

That being said, as I mentioned in "fast forward when using pull and no-ff when pull", not using --no-ff has its advantages, as it won't break git bisect and git blame.
So a developer for a feature might want to reorganize his/her feature commits (squash them a little if there are too many of them) before fast-forward them in master branch (instead of creating one giant commit).
See "Understanding the Git Workflow" for more.

这篇关于Git:仅在将外部分支合并到master中时才阻止快速合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:12