码迷,mamicode.com
首页 > 其他好文 > 详细

Git 分支合并冲突及合并分类

时间:2018-03-26 23:39:19      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:git   git分支合并   git分支合并冲突   git分支合并种类   git快速合并与普通合并   

Git 分支合并冲突及合并分类

  1. 分支合并冲突
    ##创建分支datagrand
    git checkout -b datagrand
    Switched to a new branch ‘datagrand‘
    git branch -a
    master
    \* datagrand
    ##在datagrand分支上创建文件
    echo "this is git file!" > read.txt
    git add read.txt
    git commit -m "add a new file"
    git push -u origin datagrand
    ##切换到master分支,建立read.txt文件
    echo "my name is wtf" > read.txt
    git add read.txt
    git commit -m "add a new file"
    git push 
    ##合并分支
    ##在master分支上操作
    git merge datagrand
    ##说明:这种情况下,Git无法执行“快速合并”,只能试图把各自的修改合并起来,但这种合并就可能会有冲突,报错如下:
    Auto-merging read.txt
    CONFLICT (add/add): Merge conflict in read.txt
    Automatic merge failed; fix conflicts and then commit the result.
    ##说明:Git告诉我们read.txt文件存在冲突,必须手动解决冲突后再提交。
  2. 解决合并冲突
    ##查看下当前分支状态
    git status
    On branch master
    Your branch is up-to-date with ‘origin/master‘.
    You have unmerged paths.
    (fix conflicts and run "git commit")
    (use "git merge --abort" to abort the merge)
    Unmerged paths:
    (use "git add <file>..." to mark resolution)
    both added:      read.txt
    no changes added to commit (use "git add" and/or "git commit -a")
    ##查看一下readme.txt中的内容
    cat read.txt
    <<<<<<< HEAD
    my name is wtf!
    =======
    this is git file!
    \>>>>>>> datagrand
    ##说明:Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,让我们选择要保留的内容,下面我们修改一下readme.txt,再次提交。
    ##操作步骤如下:
    vim read.txt
    git add read.txt
    git commit -m "fixed"
    [master 935e613] fixed
    git status
    On branch master
    Your branch is ahead of ‘origin/master‘ by 2 commits.
    (use "git push" to publish your local commits)
    nothing to commit, working tree clean
    cat read.txt
    this is git file!
    ##分支合并
    git merge datagrand
    ##查看合并后状态
    git status
    On branch master
    Your branch is ahead of ‘origin/master‘ by 2 commits.
    (use "git push" to publish your local commits)
    nothing to commit, working tree clean
  3. 删除分支
    git branch -d datagrand
    Deleted branch datagrand (was 3299654).
    ##查看一下分支合并信息
    git log --graph --pretty=oneline --abbrev-commit 
    \*   935e613 (HEAD -> master) fixed
    || * 3299654 (origin/datagrand) add a new file
    \* | d4f781c (origin/master) add a file read
    \* | ddb3e06 Delete read.txt
    \* | 13bfb1c add a file read
    |/
  4. 合并分支(普通合并)
    分支合并分为快速合并与普通合并两种模式,普通合并,合并后的历史有分支记录,能看出来曾经做过合并,而快速合并就看不出来曾经做过合并。下面我们来演示一下普通合并:
    (未完待续)
    。。。。。。。。。。。。。。。。。。。。。

Git 分支合并冲突及合并分类

标签:git   git分支合并   git分支合并冲突   git分支合并种类   git快速合并与普通合并   

原文地址:http://blog.51cto.com/wutengfei/2091410

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!