您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
36 不同人修改了同文件的同一...
发布时间:2020-08-01 12:40:33编辑:雪饮阅读()
首先我们还是和之前一样先把a端和b端都pull下获取并合并到最新
然后我们a端修改index.md的第2行并且添加了暂存区和提交了但没有push
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ vi index.md
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git add index.md
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git commit -m "a port two edit"
[test34 2a81a5c] a port two edit
1 file changed, 1 insertion(+), 1 deletion(-)
此时在b端我们也修改index.md的第二行并且添加了暂存区和提交了也push了
[root@localhost moral2]# vi index.md
[root@localhost moral2]# git add index.md
[root@localhost moral2]# git commit -m "b port edit big bi borther"
[test34 4dd1ed0] b port edit big bi borther
1 file changed, 1 insertion(+), 1 deletion(-)
[root@localhost moral2]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 312 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To git@github.com:xueyin220807/moral.git
151d3d9..4dd1ed0 test34 -> test34
此时我们回到a端将刚才a端没有push的进行push
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git push
To github.com:xueyin220807/moral.git
! [rejected] test34 -> test34 (fetch first)
error: failed to push some refs to 'git@github.com:xueyin220807/moral.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.
这里再次遭遇冲突,这次我们直接使用自动fetch和merge,发现git自动fetch和merge也没有用了,毕竟是在同一行(同一区域),那么决定权肯定在于自己咯。
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), 292 bytes | 19.00 KiB/s, done.
From github.com:xueyin220807/moral
151d3d9..4dd1ed0 test34 -> origin/test34
Auto-merging index.md
CONFLICT (content): Merge conflict in index.md
Automatic merge failed; fix conflicts and then commit the result.
然后我们直接vi打开提示中的冲突文件,会发现冲突的地方有标记,其中红色箭头指示区域就是我们本地本次修改的,而另外这个颜色的箭头对所指示的区域就是远端这里即是b端修改的
那么我们这里是希望两个都要则我们直接把两个指示区域的<、>、=这几个分隔符以及指示的logid全都移除即可。
此时我们查看下我们的状态,发现这里给了我们接下来两个操作选择,要提交或者放弃合并(恢复到合并之前)
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34|MERGING)
$ git status
On branch test34
Your branch and 'origin/test34' 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: index.md
no changes added to commit (use "git add" and/or "git commit -a")
那么我们这里当然是要提交了。
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34|MERGING)
$ git commit -am "settle conflict"
[test34 f72dd87] settle conflict
然后我们再次push即可
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git push
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 12 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 583 bytes | 583.00 KiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
To github.com:xueyin220807/moral.git
4dd1ed0..f72dd87 test34 -> test34
关键字词:conflict,不同人,同文件,同区域