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是在其它分支下修改的内容
    需要在这个两个版本中选择一个,然后把标记符号也要一起删除
    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
    =======
    >>>>>>> psr/psr-02
    
    vim psr_psr-02.txt
    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
    =======
    >>>>>>> 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