【问题标题】:How do I make git merge's default be --no-ff --no-commit?如何使 git merge 的默认值为 --no-ff --no-commit?
【发布时间】:2011-07-28 00:02:24
【问题描述】:

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

我如何将--no-ff--no-commit 设为所有分支的默认设置?

(自从提出这个问题以来,多年来我已经了解到,我几乎总是对提交感到满意,因此允许它默认提交更简单,只要我在执行之前修改或以其他方式解决问题推送的东西都很好……)

【问题讨论】:

标签: git merge


【解决方案1】:

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

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

但是,问题在于git pull = git fetch + git merge。因此,每当您从远程服务器拉取数据时,当需要进行简单的快进时,您将创建一个丑陋的合并提交。要解决这个问题,请将pull.ff 设置为yes

git config --global pull.ff yes

【讨论】:

  • 虽然在使用 mergeoptions 时这是正确的,但应该注意的是,如果您使用的是 merge.ff,则它不会这样做 - 它只会影响显式合并,而 pull 仍然会执行所需的操作快进。
  • 当我使用merge.ff = nogit pull 创建合并提交。
  • 要解决这个问题,您应该使用git pull --rebase (git-scm.com/docs/git-pull) 或配置branch.autosetuprebase (git-scm.com/docs/git-config.html)
  • 或使用pull.ff = yes
【解决方案2】:

把这个放在 $HOME/.gitconfig:

[merge]
    ff = no
    commit = no

您可以使用 git-config 来执行此操作:

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

【讨论】:

  • 你确定这行得通吗?它不适合我,我必须使用 branch.master.mergeoptions="--no-ff"merge.ff="no"(请参阅下面的答案)
  • @gaizka 实际上,在 1.7.2 和 1.7.7.2 中它不起作用。我会尝试稍后再检查旧版本。
  • @Stripes 使用 git config 命令,它把它放在 [merge],而不是 [core]
【解决方案3】:

根据manual,你应该使用

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

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

【讨论】:

    【解决方案4】:

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

    git config [--global] merge.ff no
    

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

    默认行为是

    git config [--global] merge.ff yes
    

    还有

    git config [--global] merge.ff only
    

    它将拒绝非快进合并

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-17
      • 2014-03-06
      • 1970-01-01
      • 2016-05-19
      • 2016-06-09
      • 2012-02-22
      • 1970-01-01
      相关资源
      最近更新 更多