Git rebase 命令 学习心得
命令
用法1: git rebase --onto <newbase> <since> <till> 用法2: git rebase --onto <newbase> <since> 用法3: git rebase <newbase> <till> 用法4: git rebase <newbase> 用法5: git rebase -i ... 用法6: git rebase --continue 用法7: git rebase --skip 用法8: git rebase --abort
添加上可选项的命令 —
用法1: git rebase --onto <newbase> <since> <till> 用法2: git rebase --onto <newbase> <since> [HEAD] 用法3: git rebase [--onto] <newbase> [<newbase>] <till> 用法4: git rebase [--onto] <newbase> [<newbase>] [HEAD]
变基操作的过程:
- 
    首先会执行git checkout切换到<till>。 因为会切换到<till>,因此如果<till>指向的不是一个分支(如master),则变基操作是在detached HEAD(分离头指针)状态进行的,当变基结束后,还要像在“时间旅行一”中那样,对master分支执行重置以实现把变基结果记录在分支中。 
- 
    将<since>..<till>所标识的提交范围写到一个临时文件中。 <since>..<till>是指包括<till>的所有历史提交排除<since>以及<since>的历史提交后形成的版本范围。 
- 
    当前分支强制重置(git reset –hard)到<newbase>。 相当于执行:git reset –hard <newbase>。 
- 从保存在临时文件中的提交列表中,一个一个将提交按照顺序重新提交到重置之后的分支上。
- 如果遇到提交已经在分支中包含,跳过该提交。
- 如果在提交过程遇到冲突,变基过程暂停。用户解决冲突后,执行git rebase –continue继续变基操作。或者执行git rebase –skip跳过此提交。或者执行git rebase –abort就此终止变基操作切换到变基前的分支上。
把since..till的commit在newbase上重新应用一次.
可以理解为: 从since这次提交开始(不包含since), 到till为止(包含till), 所做的修改放到newbase上
Git手册说明,如果没有指定 –onto newbase, 则–onto 取值为since, 如果till没指定, 则取HEAD
以下资料来自git rebase手册
      A---B---C topic
     /
D---E---F---G master
# master..topic => A B C
git rebase master
git rebase master topic
              A'--B'--C' topic
             /
D---E---F---G master
                         H---I---J topicB
                        /
              E---F---G  topicA
             /
A---B---C---D  master
# topicA..topicB => H I J
git rebase --onto master topicA topicB
              H'--I'--J'  topicB
             /
            | E---F---G  topicA
            |/
A---B---C---D  master
以下展示一个去除某一提交的功能
E---F---G---H---I---J topicA # topicA~5 => E # topicA~3 => G # topicA~3..topicA => G..J => H I J git rebase --onto topicA~5 topicA~3 topicA E---H'---I'---J' topicA