When I do git rebase --interactive
, I have six basic commands: pick
, reword
, edit
, squash
, fixup
and exec
.
What does pick
command do? Does it cherry-pick
a commit or does it checkout
it?
Interactive rebase in Git is a tool that provides more manual control of your history revision process. When using interactive rebase, you will specify a point on your branch's history, and then you will be presented with a list of commits up until that point.
To tell Git where to start the interactive rebase, use the SHA-1 or index of the commit that immediately precedes the commit you want to modify. During an interactive rebase, when Git pauses at a commit you tagged to edit, the workflow is no different than a normal commit process — you stage files and then commit them.
In fact, cherry picks can even be used to replace rebases.
Squash commits together. Two other commands rebase interactive offers us are: squash ( s for short), which melds the commit into the previous one (the one in the line before) fixup ( f for short), which acts like “squash”, but discards this commit's message.
From the help article:
pick
pick
simply means that the commit is included. Rearranging the order of the pick commands changes the order of the commits when the rebase is underway. If you choose not to include a commit, you should delete the entire line.
For completeness, here's the other commands as well:
reword
Thereword
command is similar topick
, but after you use it, the rebase process will pause and give you a chance to alter the commit message. Any changes made by the commit are not affected.edit
If you choose toedit
a commit, you'll be given the chance to amend the commit, meaning that you can add or change the commit entirely. You can also make more commits before you continue the rebase. This allows you to split a large commit into smaller ones, or, remove erroneous changes made in a commit.squash
This command lets you combine two or more commits into a single commit. A commit is squashed into the commit above it. Git gives you the chance to write a new commit message describing both changes.fixup
This is similar tosquash
, but the commit to be merged has its message discarded. The commit is simply merged into the commit above it, and the earlier commit's message is used to describe both changes.exec
This lets you run arbitrary shell commands against a commit.
Picking a commit in an interactive rebase means that Git uses the changes made by the commit in question and commits them with the original metadata (message, author, date etc.). So a single pick
looks much like a git cherry-pick
.
On the contrary, pick
does not take the state of the whole repo in the time of the commit like git checkout
would do. Just the changes made by the commit.
According to experiments, the pick command in git's interactive rebase works the same way as git cherry-pick --ff. Which, according to the documentation, acts this way:
If the current HEAD is the same as the parent of the cherry-pick’ed commit, then a fast forward to this commit will be performed.
(see: https://git-scm.com/docs/git-cherry-pick )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With