报错提示

Need to specify how to reconcile divergent branches

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 * branch            tooltipPromptTime -> FETCH_HEAD
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.rebase false # merge
hint: git config pull.rebase true # rebase
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 --rebase, --no-rebase,
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.
keda@kedadeAir backgroud %

问题分析

我要更新到的分支的历史内容与我当前的文件的内容其实并不相同。

根据您提供的命令和输出,您似乎正在尝试将名为 tooltipPromptTime 的分支的内容合并到当前分支,但由于这两个分支有不同的历史,Git 需要知道您希望如何处理这种分歧

解决问题方案

方案一:合并(Merge)

合并(Merge):如果您希望保留两个分支的历史并创建一个合并提交,可以执行以下命令:

1
2
git config pull.rebase false
git pull origin 远程分支名字 --allow-unrelated-histories

方案二:快进(Fast-Forward)

快进(Fast-Forward):如果您希望只有在能够快进的情况下才合并分支,可以执行以下命令:

1
2
git config pull.ff only
git pull origin 远程分支名字 --allow-unrelated-histories

方案三:变基(Rebase)

变基(Rebase):如果您希望将当前分支的更改建立在 tooltipPromptTime 分支的基础上,并重写当前分支的历史,可以执行以下命令:

1
2
git config pull.rebase true
git pull origin 远程分支名字 --allow-unrelated-histories

方案四:拉取远程内容,再操作

如果只是想拉取 tooltipPromptTime 分支的内容而不合并或变基,您可以使用以下命令:

1
git fetch origin 远程分支名字

这将拉取远程分支内容,但不会更改当前的工作分支。之后,您可以选择是否要合并或变基