如何重新创建“git error fatal:Need to specify how to reconciliate divergent branches."?

moiiocjp  于 2024-01-04  发布在  Git
关注(0)|答案(1)|浏览(1205)

这个问题不是问如何修复这个错误,但如何在本地测试存储库中重新创建它,所以我可以真正理解这个错误的实际含义.我找不到一个很好的解释在这里或HEREHEREHERE .一种方法来重新创建这个错误被描述HERE,但这个描述是不完整的.
我想学习的原因是,当我试图从远程仓库(存储在其他计算机上)更新本地分支(我本地计算机上的分支)时,我遇到了git的问题。

  1. git pull
  2. git pull --ff-only
  3. git reset --hard feature/branch
  4. etc.

字符串
也看到了this question,这对我没有帮助。
似乎是一个同事强制推到了那个分支,所以我不得不重置我的本地分支?(不确定这实际上意味着什么)。我试着“重置”我的本地分支,查看上面的所有命令和this question。但是它不起作用。
最后的解决办法是做(当在该分支上时)

  1. git reset --hard 6c3b91e # <- a commit not in that branch ?????
  2. git pull --ff-only


我问同事这是怎么回事,但他无法解释为什么我必须重置到一个甚至不在分支上的提交。
因此,我想自己重现这种情况,以了解发生了什么,了解正在发生的事情(就分支,提交,索引,HEAD等而言),以更好地理解和学习Git是如何工作的。
请不要建议书籍或文章,他们从来没有解释任何错误,在一个简洁明了的方式,我可能会理解.
有趣的是,我在main分支上做了修改,但没有将其推送到远程,然后又做了一个git pull,从而重现了这个错误。但首先,昨天发生这个错误时,我不在主分支上,其次,我对分支上的任何修改都不感兴趣。我想让分支在本地与远程仓库上的分支相等。

6kkfgxo0

6kkfgxo01#

创建“diverged”分支来显示你的问题真的很简单。错误消息取决于你的特定Git版本,也可能取决于本地配置。

  1. $ git init
  2. Initialized empty Git repository in ...
  3. $ git config --unset pull.rebase
  4. $ git config --unset pull.ff
  5. $ cat > todos <<EOF
  6. > my list
  7. > EOF
  8. $ git add todos
  9. $ git commit -m 'initial todos'
  10. [master (root-commit) e729989] initial todos
  11. 1 file changed, 1 insertion(+)
  12. create mode 100644 todos
  13. $ git checkout -b original
  14. Switched to a new branch 'original'
  15. $ cat >> todos <<EOF
  16. >
  17. > milk
  18. > EOF
  19. $ git add todos
  20. $ git commit -m 'buy milk'
  21. [original 8b36329] buy milk
  22. 1 file changed, 2 insertions(+)
  23. $ git checkout -b other
  24. Switched to a new branch 'other'
  25. $ sed -i 's/^milk$/eggs/' todos
  26. $ git add todos
  27. $ git commit --amend -m 'buy eggs' # this diverges the branches. there are other possibilities, including rebase and reset
  28. [other a318636] buy eggs
  29. Date: Thu Dec 21 12:00:35 2023 +0100
  30. 1 file changed, 2 insertions(+)
  31. $ git checkout original
  32. Switched to branch 'original'
  33. $ git pull . other
  34. From .
  35. * branch other -> FETCH_HEAD
  36. hint: You have divergent branches and need to specify how to reconcile them.
  37. hint: You can do so by running one of the following commands sometime before
  38. hint: your next pull:
  39. hint:
  40. hint: git config pull.rebase false # merge
  41. hint: git config pull.rebase true # rebase
  42. hint: git config pull.ff only # fast-forward only
  43. hint:
  44. hint: You can replace "git config" with "git config --global" to set a default
  45. hint: preference for all repositories. You can also pass --rebase, --no-rebase,
  46. hint: or --ff-only on the command line to override the configured default per
  47. hint: invocation.
  48. fatal: Need to specify how to reconcile divergent branches.
  49. $ git pull --ff-only . other
  50. From .
  51. * branch other -> FETCH_HEAD
  52. hint: Diverging branches can't be fast-forwarded, you need to either:
  53. hint:
  54. hint: git merge --no-ff
  55. hint:
  56. hint: or:
  57. hint:
  58. hint: git rebase
  59. hint:
  60. hint: Disable this message with "git config advice.diverging false"
  61. fatal: Not possible to fast-forward, aborting.
  62. $

字符串

展开查看全部

相关问题