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


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

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


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

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

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

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


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

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

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

$ CD到我的项目根目录

纳米美元

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


If

git pull

不做的把戏,如果你想合并当前的变化和变化将来自分支从原点拉,然后这样做:-

git merge origin/BRANCH_NAME

之后,解决合并冲突,如果有的话,这一天就结束了。


使用选项——no-ff关闭一次快进:

git pull --no-ff

https://git-scm.com/docs/git-pull#Documentation/git-pull.txt---no-ff


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

[pull]
    ff = no

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


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


您可以在终端上尝试这一点,它实际上编辑您的<。Gitconfig >文件并设置ff = no

git config pull.ff no

我也面临着相同类型的问题,我猜我们中的许多人会面临这个问题,当我们进行结对编程时,我们也有来自其他用户的传入提交。这是我所面临的步骤,并通过git拉来解决它们——没有rebase

➜  graphql-tutorial git:(filtering)  git config pull.ff only 
➜  graphql-tutorial git:(filtering) git pull
fatal: Not possible to fast-forward, aborting.
➜  graphql-tutorial git:(filtering) git merge 
➜  graphql-tutorial git:(filtering)  git config pull.rebase false 
➜  graphql-tutorial git:(filtering) git pull                      
fatal: Not possible to fast-forward, aborting.
➜  graphql-tutorial git:(filtering) git pull --no-rebase
Merge made by the 'ort' strategy.
. <file name>
. <file name>
. <file name>
. <file name>
 5 files changed, 47 insertions(+), 9 deletions(-)
 create mode 100644 app/models/auth_token.rb


这是我的工作,你可以用它git pull -no- off


这对我很有用

git pull --rebase <remote> <branch>

git pull origin main --rebase
git pull --rebase

以上两个命令对我很有用。但唯一的问题是,我在当前分支中也看到了主分支的提交..


这对我很有用

Git pull——no-ff

如果你面对这件事

Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

然后执行以下步骤

按我 pressEsc 新闻:wq


我的解决办法可能会帮助到某人。

我得到这个错误的原因是,我没有做git签出,而是做了git checkout -b,创建了一个分支。

试着通过签出远程分支来重做这个过程。


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

当你运行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

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

git pull origin branch_name --no-ff

如果原始分支被压缩,或者有一个更改破坏了提交历史,如果你不关心本地分支提交历史,你可以重置本地分支

git checkout branchname
git reset --hard origin/branchname

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

Git拉原点-rebase


如果在未来得到这个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只