四、Git多人开发:不同人修改了同文件的相同区域如何处理?
发布日期:2021-07-01 02:08:12
浏览次数:2
分类:技术文章
本文共 4271 字,大约阅读时间需要 14 分钟。
@Author:Runsen
不同人修改了同文件的相同区域如何处理?
现在小A发现小B在h1修改自己的代码,非常的生气,决定改回来。小B也觉得不好意思,于是也决定改回来。
小B在小A之前就把User.html改回了小A,不然给小A骂死。
maoli@ubuntu:~/B/muli_person_test$ vim user.html##### 用户这是小A开发的User.html
maoli@ubuntu:~/B/muli_person_test$ vim user.htmlmaoli@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 pushDelta 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
这个时候,小B已经将之前的错误修改了,可是小A不知道。发现小B将自己的成果占为己用,真的很生气,于是赶紧去改下。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)$ cat user.html 用户这是小B开发的User.html
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)$ vim user.html 用户这是小B开发的User.html,小B你真的不要脸
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (A)$ git add user.htmlYIUYE@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 devSwitched 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 AUpdating d23e309..c096b6aFast-forward user.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)$ git pushTo 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 dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.
一样报错了,原因大家想想。就是没有pull,因为B提交了代码,A的远端并不同步。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)$ git pullremote: 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 0Unpacking objects: 100% (3/3), done.From https://gitee.com/MaoliRUNsen/muli_person_test dcff9e8..1d75f13 dev -> origin/devAuto-merging user.htmlCONFLICT (content): Merge conflict in user.htmlAutomatic merge failed; fix conflicts and then commit the result.
于是小A去pull,发现了出现CONFLICT (content): Merge conflict in user.html
,这个的意思就是内容冲突,
改回之前的代码。
最后查看下git status
,只需要使用git commit
就可以解决冲突。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev|MERGING)$ git statusOn branch devYour 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..." to mark resolution) both modified: user.htmlno 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] 解决冲突
这个时候同文件的相同区域产生的冲突就解决了。查看Git的状态,就可以提交了。
YIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)$ git statusOn branch devYour branch is ahead of 'origin/dev' by 2 commits. (use "git push" to publish your local commits)nothing to commit, working directory cleanYIUYE@DESKTOP-5EEO47M MINGW64 ~/Desktop/A/muli_person_test (dev)$ git pushCounting 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
转载地址:https://maoli.blog.csdn.net/article/details/108183818 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月17日 23时34分25秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
(XWZ)的Python学习笔记Ⅱ------面向对象编程
2019-05-01
(XWZ)的Python学习笔记Ⅲ——面向对象高级编程
2019-05-01
(XWZ)的python学习笔记Ⅳ——错误、调试和测试
2019-05-01
(XWZ)的Python学习笔记Ⅴ——I/O编程
2019-05-01
(XWZ)的python学习笔记Ⅶ——正则表达式
2019-05-01
(XWZ)的Python学习笔记Ⅷ--------numpy
2019-05-01
(XWZ)的python学习笔记——pandas
2019-05-01
基于Frobenius范数的标准NMF更新公式推导
2019-05-01
深度学习第一课——神经网络
2019-05-01
高斯混合模型
2019-05-01
(5)CMake入门笔记--CMake官网教程
2019-05-01
(6)CMake入门笔记--CMake官网教程
2019-05-01
(7)CMake入门笔记--CMake官网教程
2019-05-01
(8)CMake入门笔记--CMake语法
2019-05-01
(9)CMake入门笔记--同时生成动态库与静态库
2019-05-01
beyond compare 4 的30天试用期已过-解决方法
2019-05-01
面试海量数据问题
2019-05-01
TensorFlow图优化(一)-CSE(公共子表达式消除)
2019-05-01
TensorFlow图优化(二)-Remapper,layout
2019-05-01
TensorFlow btc allocator
2019-05-01