Git rebase: Difference between revisions
(Created page with "=Internal= * Git Commands =Overview=") |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* [[Git_Commands#Branch_Operations|Git Commands]] | * [[Git_Commands#Branch_Operations|Git Commands]] | ||
* [[Git Rebasing]] | |||
=Overview= | =Overview= | ||
<tt>git rebase</tt> reapplies commits on top of another base tip, removing the original commits. For more details on how rebasing works, and some concrete examples, see: {{Internal|Git Rebasing|Git Rebasing}} | |||
=Options= | |||
==--onto== | |||
<syntaxhighlight lang='bash'> | |||
git rebase --onto <newbase> | |||
</syntaxhighlight> | |||
Starting point at which to create the new commits. If the --onto option is not specified, the starting point is <font color=darkgray><''upstream''> (what does that mean?)</font>. It may be any valid commit, not just an existing branch name. | |||
==--fork-point== | |||
The option that allows specifying the ancestor commit after which all commits will be rebased. Normally, this is implicitly calculated by git with: | |||
<syntaxhighlight lang='bash'> | |||
git merge-base --fork-point <upstream> <branch> | |||
</syntaxhighlight> | |||
command. If fork-point ends up being empty as result of this command, <''upstream''> will be used as fallback. | |||
==="fatal: No such ref:" Error=== | |||
In situations like this one: | |||
<font size=-1> | |||
git rebase --onto develop --fork-point 17f3781e6b3cb13653b1116fe8e8823a172bc502 | |||
fatal: No such ref: '17f3781e6b3cb13653b1116fe8e8823a172bc502' | |||
</font> | |||
you can get around by specifying the fork point not as a hash, but as a tag. | |||
==-i== | |||
Interactive rebase. | |||
To include a specific number of commits, going back from HEAD, use <code>HEAD~count</code> | |||
<syntaxhighlight lang='bash'> | |||
rebase -i HEAD~10 | |||
</syntaxhighlight> | |||
To include all the commits from HEAD to, but excluding a specific commit, use: | |||
<syntaxhighlight lang='bash'> | |||
rebase -i <commit-sha-of-the-first-commit-NOT-to-be-included> | |||
</syntaxhighlight> |
Latest revision as of 19:41, 28 April 2023
Internal
Overview
git rebase reapplies commits on top of another base tip, removing the original commits. For more details on how rebasing works, and some concrete examples, see:
Options
--onto
git rebase --onto <newbase>
Starting point at which to create the new commits. If the --onto option is not specified, the starting point is <upstream> (what does that mean?). It may be any valid commit, not just an existing branch name.
--fork-point
The option that allows specifying the ancestor commit after which all commits will be rebased. Normally, this is implicitly calculated by git with:
git merge-base --fork-point <upstream> <branch>
command. If fork-point ends up being empty as result of this command, <upstream> will be used as fallback.
"fatal: No such ref:" Error
In situations like this one:
git rebase --onto develop --fork-point 17f3781e6b3cb13653b1116fe8e8823a172bc502 fatal: No such ref: '17f3781e6b3cb13653b1116fe8e8823a172bc502'
you can get around by specifying the fork point not as a hash, but as a tag.
-i
Interactive rebase.
To include a specific number of commits, going back from HEAD, use HEAD~count
rebase -i HEAD~10
To include all the commits from HEAD to, but excluding a specific commit, use:
rebase -i <commit-sha-of-the-first-commit-NOT-to-be-included>