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]#