Interactive Rebase in Git
Interactive Rebase Commands
Interactive Rebase Commands
During an interactive rebase, you will encounter a series of commands that allow you to modify the commit history in various ways. Below are detailed descriptions of the most common commands you can use during an interactive rebase in Git.
Main Commands
pick
(or p
)
Use the commit as is, without making any changes.
Example:
plaintext
reword
(or r
)
Modify the commit message without changing its content.
Example:
plaintext
After applying this command, the editor will open for you to change the commit message.
edit
(or e
)
Stop the rebase at the specified commit so you can modify its content.
Example:
plaintext
squash
(or s
)
Combine this commit with the previous one and allow you to edit the combined commit message.
Example:
plaintext
fixup
(or f
)
Similar to squash
, but discards the current commit message and uses the previous commit's message.
Example:
plaintext
exec
(or x
)
Execute a shell command.
Example:
plaintext
drop
(or d
)
Discard the specified commit.
Example:
plaintext
Combining Commands
It is possible to combine several commands in a single interactive rebase session. For example, you might have a configuration like the following:
plaintext
In this scenario, the interactive rebase will apply the first commit as is (pick
), allow you to change the message of the second commit (reword
), stop the rebase to modify the third commit (edit
), and finally combine the fourth commit with the third one (squash
).