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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5519007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:30:36  来源:igfitidea点击:

How do I make git merge's default be --no-ff --no-commit?

gitmerge

提问by Stripes

Company policy is to use --no-fffor merge commits. I personally like to adjust merge log messages so I use --no-commit. Plus I like to actually compile and test before I let the commit go.

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

How do I make --no-ffand --no-committhe default for me for all branches?

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

(and I've learned in the years since asking this, I almost always am happy with the commit, so it is simpler to allow it to commit by default and so long as I amend or otherwise fix things up before doing a push things are all good...)

(自从问这个问题以来,我在这些年里学到了,我几乎总是对提交感到满意,所以默认情况下允许它提交更简单,只要我在做推送之前修改或以其他方式修复问题是都好...)

回答by William Pursell

Put this in $HOME/.gitconfig:

把它放在 $HOME/.gitconfig 中:

[merge]
    ff = no
    commit = no

You can use git-config to do this:

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

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

回答by Jian

To make --no-ff --no-committhe default merge behavior, set the options to nousing:

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

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

However, the problem with this is that git pull= git fetch+ git merge. So whenever you pull from the remote server, you'd be creating an ugly merge commit when a simple fast-forward would be warranted. To solve this, set pull.ffto yes:

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

git config --global pull.ff yes

回答by gaizka

As of version 1.7.6 of git, you should use

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

git config [--global] merge.ff no

to "force" using --no-ffin every merge.

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

Default behaviour is

默认行为是

git config [--global] merge.ff yes

And with

git config [--global] merge.ff only

it will refuse non-fast-forward merges

它将拒绝非快进合并

回答by alexglue

According to manual, you should use

根据手册,您应该使用

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

to set no-fast-forward option by default for all branches with git-config utility.

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