处理git pull冲突

git pull同步远程仓修改到本地仓;
当远程仓的有人提交的修改和本地修改的是同一行时,git可能不知道应该保留哪个修改而产生冲突。
实例演示:
1.修改github上面的test.sh,在world后加!并commit.
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2.修改本地仓的test.sh
比如远程仓有人提交的bs.html和我本地仓commit的bs.html修改存在冲突,这时执行git pull会产生冲突

[root@CSDN /home/Sudley/github/git_learning]#vi test.sh
[root@CSDN /home/Sudley/github/git_learning]#git commit -am "change hello to Hello"
[main f6f6114] change hello to Hello
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@CSDN /home/Sudley/github/git_learning]#git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/Sudley/git_learning
   d38ce8e..e8af234  main       -> origin/main
Auto-merging test.sh
CONFLICT (content): Merge conflict in test.sh
Automatic merge failed; fix conflicts and then commit the result.
[root@CSDN /home/Sudley/github/git_learning]#

3.处理冲突
打开test.sh文件发现git标记了冲突位置

[root@CSDN /home/Sudley/github/git_learning]#vi test.sh
<<<<<<< HEAD
echo "Hello world"
=======
echo "hello world!"
>>>>>>> e8af2340bcfcdef0a0a35b06a70ff9b8bf470c1c

修改后提交

[root@CSDN /home/Sudley/github/git_learning]#cat test.sh
echo "Hello world!"
[root@CSDN /home/Sudley/github/git_learning]#git status
# On branch main
# Your branch and 'origin/main' have diverged,
# and have 1 and 1 different commit each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
# You have unmerged paths.
#   (fix conflicts and run "git commit")    #存在冲突
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      test.sh
no changes added to commit (use "git add" and/or "git commit -a")
[root@CSDN /home/Sudley/github/git_learning]#git commit -am "fix merge conflicts"
[main ddfc0b1] fix merge conflicts
[root@CSDN /home/Sudley/github/git_learning]#git status    #处理完冲突后
# On branch main
# Your branch is ahead of 'origin/main' by 2 commits.
#   (use "git push" to publish your local commits)
#
[root@CSDN /home/Sudley/github/git_learning]#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值