fatal: Need to specify how to reconcile divergent branches. fatal: Not possible to fast-forward, aborting.
- 我想要拉取
github远程仓库,报了错误
PS D:\workspace\blogs\hexo> git pull origin main
From github.com:quiezx/quiezx.github.io
* branch main -> 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.
解决方案
- 执行该命令
git pull --ff-only origin main
- 执行这个命令后可能会报这个错误
fatal: Not possible to fast-forward, aborting.
- 执行该命令
git pull origin main --rebase
分析总结
Need to specify how to reconcile divergent branches 出现这个错误的原因是 git pull 会创建一次合并提交,他会创建以前不存在的提交 SHA 散列值
When you do a
git pull origin master,
git pullperforms a merge, which often creates a merge commit. Therefore, by default, pulling from the remote is not a harmless operation: it can create a new commit SHA hash value that didn’t exist before. This behavior can confuse a user, because what feels like it should be a harmless download operation actually changes the commit history in unpredictable ways.
fatal: Not possible to fast-forward, aborting. 这个错误可能是没设置远程分支导致的
参考链接
https://stackoverflow.com/questions/62653114/how-can-i-deal-with-this-git-warning-pulling-without-specifying-how-to-reconci
https://stackoverflow.com/questions/13106179/error-fatal-not-possible-to-fast-forward-aborting