Forrest logo
back to the git tool

git-rebase:tldr:9640a

git-rebase: Start an interactive rebase, which allows the commits to be reordered, omitted, combined or modified.
$ git rebase -i ${target_base_branch_or_commit_hash}
try on your machine

The command git rebase -i ${target_base_branch_or_commit_hash} is used to perform an interactive rebase in Git.

Here's a breakdown of the different components of the command:

  • git rebase: This is the command that initiates the rebase operation in Git.
  • -i: This flag stands for "interactive," indicating that the rebase will be performed in interactive mode. This allows you to modify and alter the commit history during the rebase process.
  • ${target_base_branch_or_commit_hash}: This is a placeholder that represents the base branch or commit hash that you want to rebase onto. It can be either a branch name or a specific commit hash that you want to use as the base for the rebase operation.

When you run the command, Git will open up an interactive editor session (usually using the default text editor set in your Git configuration) that displays a list of commits being rebased. Each commit will have an associated command prefix (e.g., pick, edit, squash, reword, etc.) that you can modify to alter the commit history.

You can modify the order, merge, squash, edit, or even discard commits based on your requirements. By saving and closing the editor, Git will apply the changes and perform the rebase operation according to the modified commit list.

Using interactive rebase provides a flexible way to change the commit history, combine multiple commits into one, split a commit into multiple commits, edit commit messages, and more.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool