git merge 之提交分支远程合并后再同步本地合并时冲突

发布于:2024-10-09 ⋅ 阅读:(5) ⋅ 点赞:(0)

$ git fetch
remote: Counting objects: 56639, done
remote: Finding sources: 100% (27/27)
remote: Total 27 (delta 21), reused 26 (delta 21)
Unpacking objects: 100% (27/27), 4.13 KiB | 4.00 KiB/s, done.
From ssh://192.168.179.244:29418/project
   dd43db4c..ead4e888  develop -> origin/develop

$ git merge
Auto-merging ac/sync.cpp
CONFLICT (content): Merge conflict in ac/sync.cpp
Automatic merge failed; fix conflicts and then commit the result.

$ git status
On branch develop
Your branch and 'origin/develop' have diverged,
and have 1 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   ac/sync.cpp


$ git fetch
$ git merge

error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

分析:
此次冲突为本地推送了分支到远程,代码管理同事做了其它修改后并合并了此分支到一个新节点,导致远程分支已没有本地刚推送的分支节点,此时合并远程分支,就出现了冲突。

解决:
1.git reset --hard dd43db4c 回退到冲突之前的最新版本。
2.git fetch
3.git merge
4.合并分支为同步到远程分支,已为最新提交