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

Str*_*pes 67 git merge

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

如何为所有分支制作--no-ff--no-commit默认?

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

Wil*_*ell 100

把它放在$ HOME/.gitconfig中:

[merge]
    ff = no
    commit = no
Run Code Online (Sandbox Code Playgroud)

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

  git config --global merge.commit no
  git config --global merge.ff no
Run Code Online (Sandbox Code Playgroud)

  • 你确定这有效吗?它不适合我,我必须使用 `branch.master.mergeoptions="--no-ff"` 或 `merge.ff="no"` (参见下面的答案) (3认同)
  • 这对我不起作用。也许 git 甚至没有 merge.commit 选项,请参阅 [git-merge-with-no-commit-as-default](/sf/ask/4943074881/作为默认) (2认同)

Jia*_*ian 35

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

git config --global merge.ff no
git config --global merge.commit no
Run Code Online (Sandbox Code Playgroud)

但是,问题在于git pull= git fetch+ git merge.因此,无论何时从远程服务器拔出,都需要创建一个丑陋的合并提交,这样才能保证简单的快进.要解决此问题,请设置pull.ffyes:

git config --global pull.ff yes
Run Code Online (Sandbox Code Playgroud)

  • 虽然在使用mergeoptions时也是如此,但应该注意的是,如果你使用`merge.ff`而不是这样做 - 它只会影响显式合并,而pull仍然会执行所需的快进. (17认同)
  • 或者使用`pull.ff = yes` (8认同)
  • 当我使用`merge.ff = no`时,`git pull`会创建合并提交. (3认同)
  • 要解决这个问题,你应该使用`git pull --rebase`(http://git-scm.com/docs/git-pull)或配置`branch.autosetuprebase`(http://git-scm.com/docs/ GIT-config.html) (3认同)

gai*_*zka 20

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

git config [--global] merge.ff no
Run Code Online (Sandbox Code Playgroud)

--no-ff在每次合并中"强制"使用.

默认行为是

git config [--global] merge.ff yes
Run Code Online (Sandbox Code Playgroud)

git config [--global] merge.ff only
Run Code Online (Sandbox Code Playgroud)

它将拒绝非快进合并


ale*_*lue 10

根据手册,你应该使用

$ git config [--global] merge.ff false
Run Code Online (Sandbox Code Playgroud)

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