美文网首页
分支冲突解决

分支冲突解决

作者: INGME | 来源:发表于2017-12-15 19:19 被阅读0次
    1.1准备新的feature1分支,继续我们的新分支开发:
    $ git checkout -b feature1
    Switched to a new branch 'feature1'
    
    1.2修改readme.txt最后一行,改为:
    Creating a new branch is quick AND simple.
    
    1.3在feature1分支上提交:
    $ git add readme.txt 
    $ git commit -m "AND simple"
    [feature1 75a857c] AND simple
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    1.4切换到master分支:
    $ git checkout master
    Switched to branch 'master'
    Your branch is ahead of 'origin/master' by 1 commit.
    
    1.5在master分支上把readme.txt文件的最后一行改为:
    Creating a new branch is quick & simple.
    
    1.5提交:
    $ git add readme.txt 
    $ git commit -m "& simple"
    [master 400b400] & simple
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    1.6现在,master分支和feature1分支各自都分别有新的提交,变成了这样:
    0.png
    1.6这种情况下,Git无法执行“快速合并”,只能试图把各自的修改合并起来,但这种合并就可能会有冲突
    $ git merge feature1
    Auto-merging readme.txt
    CONFLICT (content): Merge conflict in readme.txt
    Automatic merge failed; fix conflicts and then commit the result.
    
    image.png
    1.7Git用<<<<<<<=======>>>>>>>标记出不同分支的内容,我们修改如下后保存:
    Creating a new branch is quick and simple.
    
    1.8现在,master分支和feature1分支变成了下图所示:
    1.png
    1.9用带参数的git log --graph可以看到分支的合并情况:
    $ git log --graph --pretty=oneline --abbrev-commit
    *   59bc1cb conflict fixed
    |\
    | * 75a857c AND simple
    * | 400b400 & simple
    |/
    * fec145a branch test
    ...
    
    image.png
    2.0最后,删除feature1分支:
    $ git branch -d feature1
    Deleted branch feature1 (was 75a857c).
    

    相关文章

      网友评论

          本文标题:分支冲突解决

          本文链接:https://www.haomeiwen.com/subject/hogdwxtx.html