2015-12-29 22:54:20 +00:00
|
|
|
# git rebase
|
|
|
|
|
2017-04-23 11:11:31 +01:00
|
|
|
> Reapply commits from one branch on top of another branch.
|
|
|
|
> Commonly used to "move" an entire branch to another base, creating copies of the commits in the new location.
|
2019-06-03 01:06:36 +01:00
|
|
|
> More information: <https://git-scm.com/docs/git-rebase>.
|
2015-12-29 22:54:20 +00:00
|
|
|
|
2020-10-19 19:26:01 +01:00
|
|
|
- Rebase the current branch on top of another specified branch:
|
2015-12-29 22:54:20 +00:00
|
|
|
|
2020-10-19 19:26:01 +01:00
|
|
|
`git rebase {{new_base_branch}}`
|
2015-12-30 17:36:58 +00:00
|
|
|
|
2016-11-09 18:20:40 +00:00
|
|
|
- Start an interactive rebase, which allows the commits to be reordered, omitted, combined or modified:
|
2015-12-30 17:36:58 +00:00
|
|
|
|
2024-09-03 01:43:42 +01:00
|
|
|
`git rebase {{-i|--interactive}} {{target_base_branch_or_commit_hash}}`
|
2015-12-30 17:36:58 +00:00
|
|
|
|
2016-11-09 18:20:40 +00:00
|
|
|
- Continue a rebase that was interrupted by a merge failure, after editing conflicting files:
|
2015-12-30 17:36:58 +00:00
|
|
|
|
|
|
|
`git rebase --continue`
|
|
|
|
|
2019-07-07 10:01:27 +01:00
|
|
|
- Continue a rebase that was paused due to merge conflicts, by skipping the conflicted commit:
|
|
|
|
|
|
|
|
`git rebase --skip`
|
|
|
|
|
2016-11-09 18:20:40 +00:00
|
|
|
- Abort a rebase in progress (e.g. if it is interrupted by a merge conflict):
|
2015-12-30 17:36:58 +00:00
|
|
|
|
|
|
|
`git rebase --abort`
|
2016-09-21 07:58:28 +01:00
|
|
|
|
2017-04-23 11:11:31 +01:00
|
|
|
- Move part of the current branch onto a new base, providing the old base to start from:
|
2016-09-21 07:58:28 +01:00
|
|
|
|
2017-04-23 11:11:31 +01:00
|
|
|
`git rebase --onto {{new_base}} {{old_base}}`
|
|
|
|
|
2017-04-26 08:29:34 +01:00
|
|
|
- Reapply the last 5 commits in-place, stopping to allow them to be reordered, omitted, combined or modified:
|
2017-04-23 11:11:31 +01:00
|
|
|
|
2024-09-03 01:43:42 +01:00
|
|
|
`git rebase {{-i|--interactive}} {{HEAD~5}}`
|
2019-07-07 10:09:21 +01:00
|
|
|
|
|
|
|
- Auto-resolve any conflicts by favoring the working branch version (`theirs` keyword has reversed meaning in this case):
|
|
|
|
|
2024-09-03 01:43:42 +01:00
|
|
|
`git rebase {{-X|--strategy-option}} theirs {{branch_name}}`
|