Git rebase的应用
Git的官方手册上,这么解释rebase的
Forward-port local commits to the updated upstream head
很简单的一句话,确实很让人迷惑...
简单的说,就是把在一个分支里提交的改变应用在另一个分支里
从这层意义上讲,git rebase是类似git merge的
它们最终的结果是一致的,都是合并2个分支的内容
但是,git rebase合并后的commit信息是一个线性的,没有分叉,看起来比较整洁
以下,引用progit中的几个图示
例如:我们原始有2个分支:master和expriment
这2个分支都有自己的一个commit信息
如果,我们使用git merge来合并
那么,合并后的大概是这样
如果,我们使用git rebase来操作
git checkout master
git rebase expriment
git checkout master
git fetch
git rebase origin/master
它的操作过程是
git rebase origin/master will take the local commits (that are reachable from the master head, but not from origin/master), remove them from the commit tree, and re-apply them on top of origin/master
看一下这个图示,就大概明白了
除了合并代码外,rebase还可以修正本地的commmit信息
可以参考
Git往远程push前修改commit信息
使用rebase的一个重要原则
永远不要衍合那些已经push到remote server上的commit