The git rebase
command makes it easy to change a your commit history, meaning you can alter your commits which will change your repository's history. You can edit, combine, or rearrange commits.
Generally, git rebase
is used for modify earlier commit messages, Combine multiple commits into a single one and remove or revert unnecessary commits.
There are multiple commands you can use with git rebase
edit
will give you the option to edit a commit, which will allow you to either add to or completely alter the commit. Before continuing the rebase, you can add more commits. With this command, you can remove incorrect changes that were made in a commit or divide a big commit into smaller ones.pick
indicates that the commit is present. When the rebase is in progress, rearranging the pick commands will alter the order of the commits. If you decide against adding a commit, remove the entire line.squash
allows you to combine multiple commits into one. The current commit will be squashed with the commit that precedes it and add a descriptive message of the changes made.reword
is just likeedit
but unlike editreword
allows you to change the commit message and not the contents of it.fixup
is similar tosquash
but unlikesquash
,fixup
does not allow us to write a message to describe the changes that were made. The message will be discarded and the merge of both commits will have the previous commit's descriptive message.
How Do You Use Git Rebase ?
Standard and interactive are the two distinct Git rebase modes. a typical mode Git rebase automatically snatches up the commits in your active working branch and applies them right away to the passed branch's head.
As opposed to gathering everything and dumping it into the passed branch, Interactive mode allows you to change various commits throughout the process. You can edit the history and remove, split, or change existing commits if you use interactive mode.
Standard git rebase
git rebase <base>
Interactive git rebase
git rebase --interactive <base>
or
git rebase -i <base>
With this command, an editor is opened into which you can enter commands for each commit you wish to rebase.
git rebase commands | description |
---|---|
git rebase --continue |
This is used to keep the changes made. |
$ git rebase --skip |
This command is used to skip the changes that were made |
git rebase -i |
This will list all interactive options which we've mentioned above |
Top comments (0)