git合并冲突解决方法
2017-04-13 22:32
495 查看
1、git merge冲突了,根据提示找到冲突的文件,解决冲突
如果文件有冲突,那么会有类似的标记
2、修改完之后,执行git add 冲突文件名
3、git commit
进去类似于vim的操作界面,把conflict相关的行删除掉
4、直接push就可以了,因为刚刚已经执行过相关merge操作了
相关的操作如下
冲突产生
冲突解决过程
冲突文件的格式基本如下
冲突文件
修改冲突文件
添加冲突的文件,然后就可以直接push了
需要删掉下面这两行
执行git push 操作
如果文件有冲突,那么会有类似的标记
2、修改完之后,执行git add 冲突文件名
3、git commit
注意:没有-m选项
进去类似于vim的操作界面,把conflict相关的行删除掉
4、直接push就可以了,因为刚刚已经执行过相关merge操作了
相关的操作如下
冲突产生
[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' #提交到暂存区 [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.
冲突解决过程
冲突文件的格式基本如下
<<<<<<<到=======是在当前分支合并之前的文件内容 =======到>>>>>>> psr/psr-02是在其它分支下修改的内容 需要在这个两个版本中选择一个,然后把标记符号也要一起删除
<<<<<<< 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
执行git push 操作
git push origin master
相关文章推荐
- Git 合并时冲突 Merge Conflict:file still marked as conflicted 解决方法
- Git 合并时冲突 Merge Conflict:file still marked as conflicted 解决方法
- Eclipse的Git插件Egit: merge合并冲突具体解决方法
- Git技巧之解决git merge的合并冲突(非树冲突)
- Git系列之合并冲突解决
- git 本地库推送远程库 版本冲突的解决方法
- git 解决分支冲突的方法
- git 解决分支冲突的方法
- git中的文件冲突解决方法
- Git:代码冲突常见解决方法
- git分支的合并和冲突解决
- Egit的merge合并冲突具体解决方法
- Git:代码冲突常见解决方法
- 如何用 Git 合并两个库(合并历史记录,解决冲突/改写路径)
- git的版本和本地版本冲突的解决方法
- git 的使用(5)-git的分支管理以及合并冲突解决
- git pull时本地文件和服务器文件冲突解决方法
- git 冲突解决方法
- 解决git中 项目合并冲突的问题