Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "pick" in Git's interactive rebase do?

Tags:

git

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?

like image 207
user983447 Avatar asked Aug 08 '17 08:08

user983447


People also ask

How does Interactive rebase work?

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.

How do I use git interactive rebase?

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.

Does rebase use cherry pick?

In fact, cherry picks can even be used to replace rebases.

How do you squash commits with interactive rebase?

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.


3 Answers

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
The reword command is similar to pick, 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 to edit 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 to squash, 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.

like image 175
Lasse V. Karlsen Avatar answered Sep 28 '22 16:09

Lasse V. Karlsen


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.

like image 44
Melebius Avatar answered Sep 28 '22 16:09

Melebius


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 )

like image 29
user983447 Avatar answered Sep 28 '22 14:09

user983447