为什么Git不允许我快进合并了?如果我试图使用——ff-only强制它,我会得到消息“致命:不可能快进,终止。”我意识到合并-no-ff有巨大的优势,但我只是不明白为什么我现在不能-ff-only ?


当前回答

这是因为您启用了“仅快进”选项。这里的问题是你从分支的拉取会在你的本地git中创建一个合并提交,而只有快进选项不允许在拉取时创建一个合并提交。

在一个大团队的情况下,你最终会在很多时候改变和解决冲突,因为每一个承诺都来自拉力。

我建议你从git本地配置文件中删除ff = only行。

$ CD到我的项目根目录

纳米美元

[pull]
        ff = only // remove this line
        rebase = false

其他回答

这对我很有用

git pull --rebase <remote> <branch>

对我来说,这是有效的,改变branch_name与实际的分支:

git pull origin branch_name --no-ff

你的分支不再直接基于你试图合并到的分支——例如,另一个提交被添加到目标分支,而这个分支并不在你的分支中。因此,您不能快进到它(因为快进要求您的分支完全包含目标分支)。

你可以在目标分支的基础上重新建立你的分支(git rebase <destination branch>)来重新提交,这样它们就会快速前进到目标分支中,或者你可以做一个常规的合并。

免责声明:这些命令将从远程分支到您的分支中带来更改。

快拉,变基。与其他解决方案不同,您不需要知道目标分支的名称。

如果你的上游分支没有设置,尝试git拉origin <branch>—rebase(在评论中归功于@Rick)

要全局设置这个选项,使用git config——global pull。rebase true(归功于@Artur Mustafin)

如果在未来得到这个git错误,这个解决方案将帮助你

从(development/master/main)导入到本地分支时出现错误: 错误信息:

hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --re base, --no-re base, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches.

解决方案: 打开.git配置文件并添加这一行 1)(拉) Ff = no 如果第一步对你不起作用,那么就应用第二步

2)git pull -ff-only或git config -global pull。ff只