For example, let's imagine that we need to rebase HEAD precisely on top of F starting from E. We're only interested in bringing F into our working branch while, at the same time, we don't want to keep D because it contains some incompatible changes. Before After A---B---C---F---G (branch) A---B---C---F---G (branch) \ \ D---E---H---I (HEAD) E---H---I (HEAD)在这种情况下,我们会说 git rebase --on F D .这意味着:In this case, we would say git rebase --onto F D. This means:将父代为 D 的 HEAD 可以到达的提交重新设置为基准,位于 F 之上. Rebase the commit reachable from HEAD whose parent is D on top of F.换句话说,将 E 的父代从 D 更改为 F .然后 git rebase --onto 的语法为 git rebase --onto< newparent>.< oldparent> .In other words, change the parent of E from D to F. The syntax of git rebase --onto is then git rebase --onto <newparent> <oldparent>.这很方便的另一种情况是,您想从当前分支中快速删除一些提交而不必进行交互式变基 :Another scenario where this comes in handy is when you want to quickly remove some commits from the current branch without having to do an interactive rebase: Before After A---B---C---E---F (HEAD) A---B---F (HEAD)在此示例中,为了从序列中删除 C 和 E ,您可以说 git rebase --onto BE 或重新设置基础 B 顶部的 HEAD ,其中旧父母是 E .In this example, in order to remove C and E from the sequence you would say git rebase --onto B E, or rebase HEAD on top of B where the old parent was E. git rebase --onto 可以更进一步.实际上,它使您可以在另一个范围内重新构建任意范围的提交.git rebase --onto can go one step further in terms of precision. In fact, it allows you to rebase an arbitrary range of commits on top of another one.这是一个例子: Before After A---B---C---F---G (branch) A---B---C---F---G (branch) \ \ D---E---H---I (HEAD) E---H (HEAD)在这种情况下,我们要在 F 的基础上将准确的范围 E --- H 重新建立基础,而忽略 HEAD 当前所在的位置指向.我们可以通过说 git rebase --on F D H 来做到这一点,这意味着:In this case, we want to rebase the exact range E---H on top of F, ignoring where HEAD is currently pointing to. We can do that by saying git rebase --onto F D H, which means:将父代为 D 的提交范围重新设置为 F 之上的 H . Rebase the range of commits whose parent is D up to H on top of F.具有提交范围的 git rebase --onto 的语法随后变为 git rebase --onto< newparent>.< oldparent><直到> .这里的技巧是记住< until> 引用的提交在该范围内 included ,并且在重新设置基准后将成为新的 HEAD 完全的.The syntax of git rebase --onto with a range of commits then becomes git rebase --onto <newparent> <oldparent> <until>. The trick here is remembering that the commit referenced by <until> is included in the range and will become the new HEAD after the rebase is complete. 这篇关于如何使用on命令在分支上使用git rebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 20:15