1、git merge沖突了,根據(jù)提示找到?jīng)_突的文件,解決沖突
如果文件有沖突,那么會有類似的標記
2、修改完之后,執(zhí)行g(shù)it add 沖突文件名
3、git commit
注意:沒有-m選項
進去類似于vim的操作界面,把conflict相關(guān)的行刪除掉
4、直接push就可以了,因為剛剛已經(jīng)執(zhí)行過相關(guān)merge操作了
相關(guān)的操作如下
沖突產(chǎn)生
[root@Monitor Demo]# git branch #當前在master分支下
* master
psr/psr-01
psr/psr-02
[root@Monitor Demo]# git checkout psr/psr-02 #切換到psr/psr-02分支下
Switched to branch 'psr/psr-02'
[root@Monitor Demo]# git branch
master
psr/psr-01
* psr/psr-02
[root@Monitor Demo]# ls
LICENSE new_remote_branch.txt psr_psr-02.txt README.md
[root@Monitor Demo]# vim psr_psr-02.txt #修改psr/psr-02分支上的文件
[root@Monitor Demo]# git add psr_psr-02.txt
[root@Monitor Demo]# git commit -m 'psr_psr-02.txt has changed on psr/psr-02 branch' #提交到暫存區(qū)
[psr/psr-02 62ca72c] psr_psr-02.txt has changed on psr/psr-02 branch
1 files changed, 6 insertions(+), 0 deletions(-)
[root@Monitor Demo]# git checkout master #切換到master分支下
Switched to branch 'master'
[root@Monitor Demo]# vim psr_psr-02.txt #在master分支下也對psr_psr-02.txt進行修改
[root@Monitor Demo]# git add psr_psr-02.txt
[root@Monitor Demo]# git commit -m 'changed this file on master branch'
[master 282fbeb] changed this file on master branch
1 files changed, 2 insertions(+), 0 deletions(-)
[root@Monitor Demo]# git merge psr/psr-02 #把psr/psr-02分支合并到當前分支,這時提示沖突了
Auto-merging psr_psr-02.txt
CONFLICT (content): Merge conflict in psr_psr-02.txt
Automatic merge failed; fix conflicts and then commit the result.
沖突解決過程
沖突文件的格式基本如下
到=======是在當前分支合并之前的文件內(nèi)容
=======到>>>>>>> psr/psr-02是在其它分支下修改的內(nèi)容
需要在這個兩個版本中選擇一個,然后把標記符號也要一起刪除
HEAD
add some lines on master branch
add some lines on psr/psr-01 branch
2016年12月13日14:43:34 changed after psr/psr-02
=======
1
2
3
4
5
>>>>>>> psr/psr-02
沖突文件
vim psr_psr-02.txt
HEAD
add some lines on master branch
add some lines on psr/psr-01 branch
2016年12月13日14:43:34 changed after psr/psr-02
=======
1
2
3
4
5
>>>>>>> psr/psr-02
修改沖突文件
# vim psr_psr-02.txt
README.md
I'am in new branch psr/psr-02 based on psr/psr-01
add some lines on master branch
add some lines on psr/psr-01 branch
2016年12月13日14:43:34 changed after psr/psr-02
添加沖突的文件,然后就可以直接push了
Merge branch 'psr/psr-02'
Conflicts:
psr_psr-02.txt
#
# It looks like you may be committing a MERGE.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
#
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
需要刪掉下面這兩行
Conflicts:
psr_psr-02.txt
執(zhí)行g(shù)it push 操作
到此這篇關(guān)于詳解git合并沖突解決方法的文章就介紹到這了,更多相關(guān)git合并沖突內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!