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


当前回答

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

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

其他回答

如果你有一个提交,尝试撤销它,再拉一次!

如果您在本地分支上执行git pull origin master时遇到此情况,请在记事本中打开.gitconfig(通常隐藏在C:\Users\Myname中)并添加这两行

[pull]
    ff = no

保存配置并再次尝试git pull origin master

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

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

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

$ CD到我的项目根目录

纳米美元

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

我什么时候能看到这条信息?

当你运行git merge——ff-only <some/branch>或git pull——ff-only <remote> <some/branch>时,你试图合并的分支或提交不是基于你当前的分支——它的历史以某种方式从你的分支分叉。

Git pull可以在配置中设置默认值,所以如果你运行一个简单的Git pull origin <some/branch>,你也可以看到这一点,并且你的配置有pull。Ff = only。 要检查你的配置:运行git config pull.ff 或者git config——show-origin pull.ff (git merge有一个类似的merge。ff选项)

我怎么才能知道什么东西不管用?

要查看你的分支和目标分支的历史,你可以使用:

git log --graph --oneline HEAD <some/branch>

如果你没有显式地输入一个分支名称(例如:git merge—ff-only或git pull—ff-only), git默认为“你的活动分支的上游分支”——通常是origin/mybranch。从命令行引用该分支的方法是@{u}:

git log --graph --oneline HEAD @{u}
# for Powershell users: @{...} is an operator, you will need to quote "@{u}"
git log --graph --oneline HEAD "@{u}"

您应该看到当前分支和目标分支之间的分歧。 参见下面的“更多git日志选项”。

我该怎么补救呢?

这取决于你想要达到的结果,以及你在上面的历史中看到的结果。

你可能想要在目标提交的基础上重新构建你的提交:

git rebase <some/branch>
# to rebase on top of your default upstream :
git rebase   # same as 'git rebase @{u}'

你可能想要运行一个实际的合并,而不是只允许快进:

git merge <some/branch>
git merge     # same as 'git merge @{u}'

或者任何符合你需要的东西:

在远程分支的顶部挑选一些你的提交, 使用git rebase -i, 以另一种方式合并……

当我跑的时候如何避免这种情况?

如果你设置了——ff-only作为默认值(例如:If git config pull. only)。Ff只返回),你可以通过显式地提供一个命令行标志来一次性覆盖这个默认值:

git pull --rebase  # rebase on top of fetched branch, rather than merge it
git pull --ff      # run a normal merge
                   # (note: you *will* have a merge commit in your history)

如果你想将默认值更改为其他值:

# remove that default value, allow normal merges when pulling
git config --global --unset pull.ff

# run `git pull --rebase` by default
#   note: you still need to run 'git config --global --unset pull.ff'
git config --global pull.rebase true

更多git日志选项

要查看终端中两个分支之间的差异:

Git log -oneline -graph a b将向您显示a和b结合在一起的完整历史。 如果你想知道a和b分叉后的历史:

git log --oneline --graph --boundary a...b

# a...b (3 dots) : means 'symmetric difference' in git log
# --boundary     : will show the commit that was at the fork point
#                  without this option, the two histories will be printed
#                  one below the other

如果你想隐藏分支——例如,如果你想查看git log my/branch…Master,但不想查看所有合并到Master的pull请求的详细信息:

git log --oneline --graph --boundary --first-parent a...b

# --first-parent : on merge commits, only follow the first parent

许多git的图形前端(Gitextensions, TortoiseGit, gitk…)在查看存储库历史记录时都有方法激活这些选项。 在您的GUI中寻找复选框,以及您可以键入…b或HEAD…@{u}。

如果你打算经常使用这些命令,为它们设置一个别名:

# example: show HEAD vs @{upstream} log
git config --global alias.whatsup 'log --oneline --graph --boundary HEAD...@{u}'

# you can now run:
git whatsup

尝试一下,会工作得很好----

Git拉原点-rebase