git之conflict的产生与解决

git之-conflict的产生与解决

1 什么时候会产生Conflict?

不同的本地分支公共远端分支的相同的文件做了修改,同时提交到本地仓库之后,此时A先将提交的代码push到了远端,此时成功,当B将自己提交的代码push的时候,会被拒绝,显示远端被占用如下:

Push

(base) shufangdeMacBook-Pro:localrepor2 shufang$ git push 
>>>>>>>
To github.com:shufang000/git-conflict-resolve.git! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:shufang000/git-conflict-resolve.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Pull

(base) shufangdeMacBook-Pro:localrepor2 shufang$ git pull  # pull,或者--allow-unrelated-histories
>>>>>>>
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:shufang000/git-conflict-resolve82193f1..04f3ccf  master     -> origin/master
Auto-merging 222222.txt
CONFLICT (content): Merge conflict in 222222.txt # 这个文件表示有冲突,本地解决就好了
Automatic merge failed; fix conflicts and then commit the result.

冲突文件样貌

<<<<<<< HEAD # 1
hvsjdvasjcvdsabcksdv dnvbkdsglregnb;rnb 222222222222
======= # 2
sfsgfegbikgfegeg 222222222222
>>>>>>> 2d705c7b159deb2068960fd1f5eeff8e58cdb11c  # 3
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222
~         # 其中1 2 3都是需要被删掉的,然后add 然后commit 然后push那就okay了

2 rebase and merge

参考博客- https://blog.csdn.net/Dream_Weave/article/details/107945383


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部