pull 分支报错 fatal: Need to specify how to reconcile divergent branches...

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
yuan@xxdeMacBook-Pro h5 % git pull origin dev
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 15 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (15/15), 12.96 KiB | 390.00 KiB/s, done.
From ssh://gitlab.tt.cn:59522/xyzh5/shake-u/h5
 * branch              dev        -> FETCH_HEAD
   432df3ba..e96d9b9f  dev        -> origin/dev
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.

原因

这是由于你拉取 pull 分支前,进行过 merge 合并更新分支操作,而其他人在你之前已经 push 过一个版本,导致版本不一致

解决

方法一:

  • 执行git config pull.rebase false
  • 默认将 pull 下来的代码与现有改动的代码进行合并
  • 但是可能会造成代码冲突,需要处理下这个问题,代码冲突如果 2 个人都改了同一个文件,需要联系之前 push 的同学,看看这块代码怎么保存

第二种解决方法:回退到合并之前的代码,在进行 pull 拉取最新代码