rebase
Moving a series of commits so they start from a different commit, by replaying each one as a new commit with a new ID.
Rebasing commits others already have gives them a conflicting history.
In more detail
git rebase main replays the current branch's own commits on top of main, so the history looks as if you started from main's latest commit and there was never a fork. The originals still exist until Git cleans them up, reachable through the reflog, but anyone who had them now has a different history. The rule: only rebase commits that exist only on your own machine; merge shared ones.
Example
git rebase mainRelated terms
- merge — Combining the work of two branches into one, either by moving a branch forward (a fast-forward) or by recording a merge commit.
- interactive rebase — A rebase that first opens a todo list in your editor, letting you reorder, reword, squash or drop commits before they are replayed.
- rewriting history — Replacing existing commits with new ones, for example with amend, rebase or reset, which gives them new IDs.
- --abort — A flag that cancels a merge, rebase or cherry-pick that has stopped part way, returning everything to how it was before you started.
- reflog — Git's local record of every position HEAD and each branch has pointed at, used to find and recover commits that no branch points at any more.
Taught in
- Installing Git, And Telling It Who You Are — Advanced Git Internals & Distributed Workflows
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- Merging: Fast Forward Or A Merge Commit — Advanced Git Internals & Distributed Workflows
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows
- Interactive Rebase: Squash, Reorder, Reword — Advanced Git Internals & Distributed Workflows
- Cherry Picking, Reflog, And Getting Work Back — Advanced Git Internals & Distributed Workflows