Introduction
Git rebase is a Git command that allows you to reapply a series of commits on top of a new base commit. This is useful for cleaning up the Git history and merging multiple branches, preserving the linear history of the repository
Git rebase visually
After rebasing the feature branch base the feature branch changes it into the master branch base.
Git rebase commands
git rebase <base>
Git rebase standard vs git rebase interactively
Rebase standard
Git Rebase Standard is a straightforward rebasing operation that reapplies a series of commits onto a new base branch. It is used to simplify the Git history, preserving a linear and clean timeline of the project.
git rebase <base>
Rebase interactive
Git Rebase Interactive provides a more advanced rebasing experience. It allows you to edit, reorder, or even squash commits interactively before reapplying them to the new base branch.
git rebase --interactive <base>
Danger of rebase
Rebasing can be dangerous if not used with caution because it modifies the Git history of a repository.
Loss of work when rebase conflict is not resolved correctly, work can be lost or overwritten.
Rebasing can make the Git history difficult to follow and understand, as it changes the order and relationship of commits.
Rebase command with options
git rebase -- d
The commit gets discarded from the final combined commit block during the playback
git rebase -- p
Not modify the commit's message or content and will still be an individual commit in the branches history
git rebase -- x
Executes a command line shell script for each marked commit during playback.