四、Git多人开发:不同人修改了同文件的相同区域如何处理?

举报
毛利 发表于 2021/07/15 02:16:54 2021/07/15
【摘要】 @Author:Runsen 不同人修改了同文件的相同区域如何处理? 现在小A发现小B在h1修改自己的代码,非常的生气,决定改回来。小B也觉得不好意思,于是也决定改回来。 小B在小A之前就把User.html改回了小A,不然给小A骂死。 maoli@ubuntu:~/B/muli_person_test$ vim user.html ##### <htm...

@Author:Runsen

不同人修改了同文件的相同区域如何处理?

现在小A发现小B在h1修改自己的代码,非常的生气,决定改回来。小B也觉得不好意思,于是也决定改回来。

小B在小A之前就把User.html改回了小A,不然给小A骂死。

maoli@ubuntu:~/B/muli_person_test$  vim user.html
#####
<html> <head>用户</head> <body> <h1>这是小A开发的User.html</h1> </body>
</html>
maoli@ubuntu:~/B/muli_person_test$  vim user.html
maoli@ubuntu:~/B/muli_person_test$ git commit -m "XXX"
[dev 1d75f13] XXX
 1 file changed, 1 insertion(+), 1 deletion(-)
maoli@ubuntu:~/B/muli_person_test$ git push
Delta compression using up to 4 threads.
压缩对象中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 274 bytes | 0 bytes/s, 完成.
Total 3 (delta 2), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/MaoliRUNsen/muli_person_test dcff9e8..1d75f13  dev -> dev

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

这个时候,小B已经将之前的错误修改了,可是小A不知道。发现小B将自己的成果占为己用,真的很生气,于是赶紧去改下。

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)
$ cat user.html
<html> <head>用户</head> <body> <h1>这是小B开发的User.html</h1> </body>
</html>
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)
$ vim user.html
<html> <head>用户</head> <body> <h1>这是小B开发的User.html,小B你真的不要脸</h1> </body>
</html>

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)
$ git add user.html

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)
$ git commit -m "小B真的不要脸"
[A c096b6a] 小B真的不要脸
 1 file changed, 1 insertion(+), 1 deletion(-)

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)
$ git checkout dev
Switched to branch 'dev'
Your branch is behind 'origin/dev' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)
$ git merge A
Updating d23e309..c096b6a
Fast-forward
 user.html | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)
$ git push

To https://gitee.com/MaoliRUNsen/muli_person_test
 ! [rejected] dev -> dev (fetch first)
error: failed to push some refs to 'https://gitee.com/MaoliRUNsen/muli_person_test'
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.

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

一样报错了,原因大家想想。就是没有pull,因为B提交了代码,A的远端并不同步。

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://gitee.com/MaoliRUNsen/muli_person_test dcff9e8..1d75f13  dev -> origin/dev
Auto-merging user.html
CONFLICT (content): Merge conflict in user.html
Automatic merge failed; fix conflicts and then commit the result.


  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

于是小A去pull,发现了出现CONFLICT (content): Merge conflict in user.html,这个的意思就是内容冲突,


在下图就很明显看到了小B改了代码,可能小B知道错了,以为小A不知道。小A看了下,就算了。

改回之前的代码。

最后查看下git status,只需要使用git commit就可以解决冲突。

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev|MERGING)
$ git status
On branch dev
Your branch and 'origin/dev' 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")

Unmerged paths:
  (use "git add <file>..." to mark resolution) both modified:   user.html

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


YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev|MERGING)
$ git commit -am "解决冲突"
[dev d613e8f] 解决冲突 
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

这个时候同文件的相同区域产生的冲突就解决了。查看Git的状态,就可以提交了。

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)
$ git status
On branch dev
Your branch is ahead of 'origin/dev' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)
$ git push
Counting objects: 4, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 580 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/MaoliRUNsen/muli_person_test 1d75f13..d613e8f  dev -> dev

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

文章来源: maoli.blog.csdn.net,作者:刘润森!,版权归原作者所有,如需转载,请联系作者。

原文链接:maoli.blog.csdn.net/article/details/108183818

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。