天天看点

git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析

git分支合并之Fast-forword(快进方式)原理剖析

  • git与svn创建分支差别

    svn创建一个分支是将文件全部拷贝一份,而git则为其新的分支创建一个指针,其性能及效率相比与svn更加高效。

  • git 默认在master分支上,我们打开.git文件夹下的HEAD文件,我们看到:
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
    此时的对应的状态图为(HEAD 指向当前分支,master指向提交):
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
  • $ git branch dev(创建一个dev 分支)
  • $ git branch(查看当前所有分支)
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
  • $ git cheeckout dev(切换到dev分支)
  • 此时查看.git文件夹下的HEAD文件,我们看到:
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
    此时的对应的状态图为:
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
  • 当我们对在dev分支上对文件修改执行 git add ,git commit 后,此时状态图变为:
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
  • 此时我们分别切换到master和dev分支上运行git log ,对比如下:
    git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析
    我们发现master上的最近提交的sha1值与dev上上一次的提交值是相同的,此时在master分支上执行git merge dev(合并分支),此时没有冲突为快进合并(Fast-forword)
git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析

此时我们分别切换到master和dev分支上运行git log ,再次对比 master 和dev上最近提交的sha1值,我们发现他们是相同的了;

git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析

此时的对应的状态图为:

git分支合并之Fast-forword(快进方式)原理剖析git分支合并之Fast-forword(快进方式)原理剖析