git协同开发时冲突的解决

假定A,B两位开发人员同时修改了一个文件A人员先提交后,B人员在提交到远程会报错,如图:

在这里插入图片描述

B人员的解决办法

1.先执行拉取操作

git pull origin master

现在文件处在,merging冲突的状态,需要手动修改文件在这里插入图片描述
把文件修改好了以后,直接git add . git commit -m “***” 后面不能带文件
然后 git push origin master

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master)
$ git pull origin master 			#B提交,发现冲突,报错
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/LORTER/hushan
 * branch            master     -> FETCH_HEAD
   9fa2045..fa57aa6  master     -> origin/master
Auto-merging huashanjianfa.txt
CONFLICT (content): Merge conflict in huashanjianfa.txt
Automatic merge failed; fix conflicts and then commit the result.

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master|MERGING)
$ vim huashanjianfa.txt		#对文件进行修改

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master|MERGING)
$ cat huashanjianfa.txt
华山剑法,天下无敌
狐冲剑法,天下第一,我的剑比岳不群更剑! edit by lhc! edit by ybq!
我的剑是我的剑,你的剑是真的剑!

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master|MERGING)
$ git status		#工作区有变动,但未提交到本地仓库
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 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:   huashanjianfa.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master|MERGING)
$ git add .			

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master|MERGING)
$ git commit -m "resover"			#提交到本地仓库
[master 787ec2a] resover

Administrator@PC201812301553 MINGW64 /d/workspaces/weChat/hushan (master)
$ git push origin master		#推送到远程
Enumerating objects: 10, done.
Counting 
发布了41 篇原创文章 · 获赞 0 · 访问量 2819

猜你喜欢

转载自blog.csdn.net/weixin_44614772/article/details/103881794