克隆一个仓库
git clone xxx zhixiang
git clone xxx guanxi
配置本地签名
git config --local user.name “zhixiang”
git config --local user.email “zhixiang@qq.com”
git config --local user.name “guanxi”
git config --local user.email “guanxi@126.com”
设置好后查看一下
git config --local -l
然后冠希编辑了README.md
vim README.md
在头部添加了一行内容
using test1
然后添加到本地暂存区
git commit -am “using test1”
同时zhixiang也编辑了README.md
vim README.md
也在头部添加了一行内容
using test1 by zhixiang
然后添加到本地暂存区
git commit -am “using test1 by zhixiang”
然后现在冠希先一步提交到远程仓库了
git push
接着zhixiang也想推送到远程仓库
git push
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://gitee.com/ajiho/test.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.
就会报错,怎么解决? 其实已经提示你了,先 pull一下
$ 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 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 333 bytes | 16.00 KiB/s, done.
From https://gitee.com/ajiho/test
65791f4…16b7b50 master -> origin/master
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
它提示Auto-merging README.md 这个文件被自动合并了,然后我们去打开它解决完冲突
<<<<<<< HEAD
using by zhixiang
=======
using test1
>>>>>>> 16b7b504b86e8c95c1d4295bf82967bd2a9bc028
冲突内容大概是这样,<<<<<<< HEAD 到 =的内容是当前仓库的内容,= 到 >>>>>>> 是别人提交的内容
到这里就需要团队成员一起协商一下
这里我们保留zhixiang的代码
所以把其它的部分删除 只留下如下内容
using by zhixiang
然后我们再次提交到暂存区
git commit -am “解决冲突完毕”
再次推送就可以了
git push
配套视频教程
https://www.bilibili.com/video/BV1sC4y1W7Jj?spm_id_from=333.337.search-card.all.click