一、简介
在我们合并代码到主分支main的时候,有时候会遇到冲突conflict的情况而无法正常合并代码,下面有两种方法可以解决此问题。
示例:假如从分支usr/kevin/AIRRUS-5933合并到main分支报错代码冲突
二、解决冲突方法
1.以main分支为主,修改usr/kevin/AIRRUS-5933分支冲突内容
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933)
$ git checkout main
~airrus-kevin-test-ms (main)
$ git pull
~airrus-kevin-test-ms (main)
$ git checkout -
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933)
$ git merge main
Auto-merging Jenkinsfile
CONFLICT (content): Merge conflict in Jenkinsfile
Auto-merging VERSION
CONFLICT (content): Merge conflict in VERSION
Auto-merging pom.xml
CONFLICT (content): Merge conflict in pom.xml
Automatic merge failed; fix conflicts and then commit the result.
~/airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git checkout . --theirs # 解决冲突:以main分支为主,修改usr/kevin/AIRRUS-5933分支冲突内容
Updated 3 paths from the index
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git status
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git add ./
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git commit -m "test"
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git push origin usr/kevin/AIRRUS-5933
2.以usr/kevin/AIRRUS-5933分支为主,修改main分支冲突内容
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933)
$ git checkout main
~airrus-kevin-test-ms (main)
$ git pull
~airrus-kevin-test-ms (main)
$ git checkout -
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933)
$ git merge main
Auto-merging Jenkinsfile
CONFLICT (content): Merge conflict in Jenkinsfile
Auto-merging VERSION
CONFLICT (content): Merge conflict in VERSION
Auto-merging pom.xml
CONFLICT (content): Merge conflict in pom.xml
Automatic merge failed; fix conflicts and then commit the result.
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git checkout . --ours # 解决冲突:以usr/kevin/AIRRUS-5933分支为主,修改main分支冲突内容
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git status
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git add ./
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git commit -m "test"
~airrus-kevin-test-ms (usr/kevin/AIRRUS-5933|MERGING)
$ git push origin usr/kevin/AIRRUS-5933
三、其他参考命令
1.git基于remote代码强行覆盖本地代码
1)从远程拉取并更新代码库
git fetch --all
2) 以远程代码为准,同步本地代码,hard强制的意思,Branch_Name为需要同步的分支名
git reset --hard Branch_Name
3) 如果第二步没有生效,执行
git pull
评论前必须登录!
注册