您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
35 不同人修改了同文件的不同...
发布时间:2020-08-01 10:24:57编辑:雪饮阅读()
Pull
Pull命令可以自动完成fetch和merge,那么我们就把我们的两个客服端都更新到最新的
不同人修改了同文件的不同地方
首先a端编辑了index.md的第二行
并且添加到暂存区以及提交了,但是先不push
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git add index.md
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git commit -m "a edit index.md two line"
[test34 d617eb5] a edit index.md two line
1 file changed, 1 insertion(+), 1 deletion(-)
此时b端去修改了index.md在末尾添加一行内容
而b端添加暂存区提交并且push了
[root@localhost moral2]# git add index.md
[root@localhost moral2]# git commit -m " b edit index.md last"
[test34 2df3af5] b edit index.md last
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
d88647d..2df3af5 test34 -> test34
然后回到a端再将a端刚才没有push的进行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.
然后我们取到远端刚才b端push的
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git fetch
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 | 18.00 KiB/s, done.
From github.com:xueyin220807/moral
d88647d..2df3af5 test34 -> origin/test34
然后查看本地当前分支与对应远端分支正好比远端多一个版本,同时比远端少一个版本
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git branch -av
master 04781a6 moral
* test34 d617eb5 [ahead 1, behind 1] a edit index.md two line
remotes/moral/branch2 9979ccc branch2dir3
remotes/moral/branch3 b07d738 modify 2.txt
remotes/moral/master 04781a6 moral
remotes/moral/newBranch1 474a767 220807
remotes/moral/temp 48142d3 modified index.html
remotes/moral/test34 d88647d Merge remote-tracking branch 'moral/test34' into test34
remotes/origin/HEAD -> origin/master
remotes/origin/branch2 9979ccc branch2dir3
remotes/origin/branch3 b07d738 modify 2.txt
remotes/origin/master 04781a6 moral
remotes/origin/newBranch1 474a767 220807
remotes/origin/temp 48142d3 modified index.html
remotes/origin/test34 2df3af5 b edit index.md last
那么接下来我们就和远端对应分支与本地我们所在分支合并
xy@DESKTOP-BG9HNHK MINGW64 ~/Desktop/web/moral (test34)
$ git merge origin/test34
Auto-merging index.md
Merge made by the 'recursive' strategy.
index.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
合并后我们可以看到我们a端刚才在第二行编辑的内容同时刚才b端在末尾编辑的内容同时存在该文件中了
接下来我们再次push就
关键字词:git,冲突,不同人,相同文件,不同区域