如何配置 "git pull --ff-only" 和 "git merge --no-ff"

How to configure "git pull --ff-only" and "git merge --no-ff"

对我来说,典型的 git 工作流程是克隆一个远程存储库并使用 git pull 使其保持最新。我不想在拉取时合并提交,所以我使用 --ff-only 选项。

我还为功能工作创建了本地分支。我想保留分支历史,所以当我将本地分支合并回我的本地克隆时,我使用 --no-ff 选项。

如何配置 git 以默认使用这些选项?目前我的 .gitconfig 看起来像这样:

[merge]
  ff = false
[pull]
  ff = only

但是,git 拉取(实际上是 git 获取和 git 合并)似乎选择了合并选项并因此创建了合并。

根据 the git-config man pagepull.ff 上的说法,情况不应该如此:

(...) When set to only, only such fast-forward merges are allowed (equivalent to giving the --ff-only option from the command line). This setting overrides merge.ff when pulling.

配置 pull.ff 已在 Git 2.x 中引入,因此它不会按预期在 Git 1.x 上运行 -- 它会可能会选择 merge.ff 配置并在执行 Pull 时使用它。