前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git 多人协作开发冲突解决——分支合并冲突

git 多人协作开发冲突解决——分支合并冲突

作者头像
ZGGSONG
发布2022-09-09 10:53:03
2.4K0
发布2022-09-09 10:53:03
举报
文章被收录于专栏:日志

详情

接上篇文章,更加严谨的来说,再修改时要创建一个新的分支进行修改,修改完成再拉取远端仓库最新版本,再进行合并,有冲突解决冲突,再push,最后在删除开发分支这样一个流程。所以现在就来简单记录分享一下如何解决合并分支冲突。

代码语言:javascript
复制
# 创建分支 (develop)
git checkout -b dev

# 新分支和本地最新的master分支内容相同,再次进行修改
vim [xxxx.md]

# 在dev分支上add && commit
git add .
git commit -m "commit on dev"

# 切换回master分支并拉去最新代码
git checkout master
git pull origin master

# 合并dev分支至master
 git merge dev

 # 若无冲突直接push
 git push origin master

 # 若有冲突直接打开冲突文件解决冲突再次提交推送即可
 vim [xxxx.md]
 git add .
 git commit -m "resolve conflict"
 git push origin master

# 删除dev分支
git branch -d dev

以下是例子:

代码语言:javascript
复制
song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master)
$ git checkout -b dev
Switched to a new branch 'dev'

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (dev)
$ vim index.html

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (dev)
$ git add .

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (dev)
$ git commit -m "zggsongadd3ondev"

[dev 5c28c74] zggsongadd3ondev
 1 file changed, 1 insertion(+)

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (dev)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master)
$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), 293 bytes | 16.00 KiB/s, done.
From ssh://git.zggsong.cn/ksat/Test
   cbf451e..294d107  master     -> origin/master
Updating cbf451e..294d107
Fast-forward
 index.html | 1 +
 1 file changed, 1 insertion(+)

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master)
$ git merge dev
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master|MERGING)
$ vim index.html

####### Conflict Content ######
<<<<<<<HEAD
  // add by ksat3
=======
  // add by zggsong3
>>>>>>> dev
####### Conflict Content ######

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master|MERGING)
$ git add .

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master|MERGING)
$ git commit -m "resolve conflict on zggsong"
[master 03a1211] resolve conflict on zggsong

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master)
$ git push origin master
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 632 bytes | 632.00 KiB/s, done.
Total 6 (delta 2), reused 0 (delta 0), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To ssh://git.zggsong.cn/ksat/Test.git
   294d107..03a1211  master -> master

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master)
$ git branch -d dev
Deleted branch dev (was 5c28c74).

song@DESKTOP-JDGUG5G MINGW64 /d/gitR/Test (master)
$

本文作者:ZGGSONG

本文链接:https://cloud.tencent.com/developer/article/2101056

版权声明:本站所有未注明转载的文章均为原创,并采用CC BY-NV-SA 4.0授权协议,转载请注明来源

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 详情
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档