1、git merge沖突了,根據(jù)提示找到?jīng)_突的文件,解決沖突
如果文件有沖突,那么會有類似的標記
2、修改完之后,執(zhí)行git add 沖突文件名
3、git commit
注意:沒有-m選項
進去類似于vim的操作界面,把conflict相關的行刪除掉
4、直接push就可以了,因為剛剛已經(jīng)執(zhí)行過相關merge操作了
相關的操作如下
沖突產(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í)行git push 操作
git push origin master
到此這篇關于詳解git合并沖突解決方法的文章就介紹到這了,更多相關git合并沖突內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
標簽:雙鴨山 鄂爾多斯 莆田 錫林郭勒盟 哈爾濱 遵義 丹東 襄陽
巨人網(wǎng)絡通訊聲明:本文標題《詳解git合并沖突解決方法》,本文關鍵詞 詳解,git,合并,沖突,解決,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。