git合并分支起冲突:CONFLICT (add/add): Merge conflict in projects/xxxx/xxxx

我们在使用git合并分支时,经常会有冲突的情况,下面我们来解决一下:

1.将代码拉到本地

git clone xxxxxxx

2.切换到你的分支

 git checkout xxx

3.推到你想要的主分支,这样就会报错提示

git pull origin developer (主分支)

4.用vscode打开文件,py里会直接显示冲突的地方

5.手动修改

6.提交修改好的代码

git add .
git commit -m 'resolve merge conflict'
git push 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当我们在Git合并分支时,如果两个分支中的同一文件的同一部分被修改了,就会发生冲突。此时,Git会提示我们手动解决冲突。以下是解决冲突的步骤: 1.使用git merge命令合并分支,如果发生冲突Git会在命令行中输出一些描述信息,以便让我们知道有冲突发生。 2.使用git status命令查看冲突的详情,Git会列出所有未合并的文件。 3.打开冲突文件,手动解决冲突Git会在冲突文件中用<<<<<<<,=======和>>>>>>>标记出不同分支的内容。我们需要根据需要修改文件,然后删除这些标记。 4.使用git add命令将修改后的文件标记为已解决冲突。 5.使用git commit命令提交合并结果。 以下是一个解决冲突的例子: ```shell $ git merge feature Auto-merging merge.txt CONFLICT (content): Merge conflict in merge.txt Automatic merge failed; fix conflicts and then commit the result. $ git status On branch main 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: merge.txt no changes added to commit (use "git add" and/or "git commit -a") $ cat merge.txt This is a line in the main branch. <<<<<<< HEAD This is a line in the feature branch. ======= This is another line in the main branch. >>>>>>> feature $ vim merge.txt $ cat merge.txt This is a line in the main branch. This is a line in the feature branch. This is another line in the main branch. $ git add merge.txt $ git commit -m "Merge feature branch" ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值