如何使git merge的默认值为--no-ff --no-commit?


80

公司政策是--no-ff用于合并提交。我个人喜欢调整合并日志消息,因此可以使用--no-commit。另外,我喜欢在放弃提交之前进行实际的编译和测试。

如何让我--no-ff--no-commit我的默认为所有分支机构?

(而且自问这个问题以来的几年来我已经学到了,我几乎总是对提交感到满意,因此默认情况下允许提交更简单,只要我在进行推送之前修改或以其他方式解决问题就可以了)都好...)


Answers:


110

把它放在$ HOME / .gitconfig中:

[merge]
    ff = no
    commit = no

您可以使用git-config来做到这一点:

  git config --global merge.commit no
  git config --global merge.ff no

1
您确定这有效吗?它不适合我,我不得不使用或branch.master.mergeoptions="--no-ff"merge.ff="no"(请参阅下面的答案)
gaizka,2012年

@gaizka实际上,在1.7.2和1.7.7.2中,它不起作用。稍后,我将尝试花一些时间检查较旧的版本。
威廉·珀塞尔

@Stripes使用git config命令,将其放入[合并],而不是[核心]
Tisch

39

要进行--no-ff --no-commit默认的合并行为,请将选项设置为no使用:

git config --global merge.ff no
git config --global merge.commit no

但是,这样做的问题是git pull= git fetch+ git merge。因此,每当从远程服务器中拉出时,当需要进行简单的快速转发时,您都将创建一个丑陋的合并提交。要解决此问题,请设置pull.ffyes

git config --global pull.ff yes

17
尽管在使用mergeoptions时确实如此,但应注意,如果您使用的是merge.ff替代选项,则不会这样做-它仅影响显式合并,而pull仍会实现所需的快速前进。
尼克(Nick)

3
当我使用时merge.ff = nogit pull创建合并提交。
Matt McClure

3
要解决这个问题,你应该使用git pull --rebasegit-scm.com/docs/git-pull)或配置branch.autosetuprebasegit-scm.com/docs/git-config.html
Cybot

8
或使用pull.ff = yes
gabeio

20

从git 1.7.6版本开始,您应该使用

git config [--global] merge.ff no

--no-ff在每个合并中“强制”使用。

默认行为是

git config [--global] merge.ff yes

git config [--global] merge.ff only

它将拒绝非快进合并


10

根据手册,您应该使用

$ git config [--global] merge.ff false

默认情况下,使用git-config实用程序为所有分支设置no-fast-forward选项。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.