• 6. 解决合并的冲突

    教程1 操作分支

    6. 解决合并的冲突

    把issue2分支和issue3分支的修改合并到master。

    切换master分支后,与issue2分支合并。

    1. $ git checkout master
    2. Switched to branch 'master'
    3. $ git merge issue2
    4. Updating b2b23c4..8f7aa27
    5. Fast-forward
    6. myfile.txt | 2 ++
    7. 1 files changed, 2 insertions(+), 0 deletions(-)

    执行fast-forward(快进)合并。

    目前的历史记录

    接着合并issue3分支。

    1. $ git merge issue3
    2. Auto-merging myfile.txt
    3. CONFLICT (content): Merge conflict in myfile.txt
    4. Automatic merge failed; fix conflicts and then commit the result.

    自动合并失败。由于在同一行进行了修改,所以产生了冲突。这时myfile.txt的内容如下:

    1. 连猴子都懂的Git命令
    2. add 把变更录入到索引中
    3. <<<<<<< HEAD
    4. commit 记录索引的状态
    5. =======
    6. pull 取得远端数据库的内容
    7. >>>>>>> issue3

    请修改

    在发生冲突的地方,Git生成了内容的差异。请做以下修改:

    1. 连猴子都懂的Git命令
    2. add 把变更录入到索引中
    3. commit 记录索引的状态
    4. pull 取得远端数据库的内容

    修改冲突的部分,重新提交。

    1. $ git add myfile.txt
    2. $ git commit -m "合并issue3分支"
    3. # On branch master
    4. nothing to commit (working directory clean)

    历史记录如下图所示。因为在这次合并中修改了冲突部分,所以会重新创建合并修改的提交记录。这样,master的HEAD就移动到这里了。这种合并不是fast-forward合并,而是non fast-forward合并。

    目前的历史记录

    前一页

    下一页