14

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?

Melebius
  • 6,183
  • 4
  • 39
  • 52
user983447
  • 1,598
  • 4
  • 19
  • 36
  • Possible duplicate of [How can I merge two commits into one?](https://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one) – jopasserat Aug 08 '17 at 09:04
  • 1
    No, it is not a duplicate of it. https://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one does not answer the question "does it cherry-pick or checkout". – user983447 Aug 09 '17 at 03:56
  • you might want to check the accepted answer.... https://stackoverflow.com/a/2568581/470341 – jopasserat Aug 09 '17 at 10:07
  • @user983447 Has any of the answers helped you? Please [accept](https://stackoverflow.com/help/accepted-answer) it. If not, please [edit your question](https://stackoverflow.com/posts/45563865/edit) to clarify your needs. – Melebius Aug 11 '17 at 06:03

5 Answers5

15

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.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Not sure if I understand it right. When I used "pick" to include a commit, it actually takes the changes we have in that commit, and generate a new commit. So although the "picked" commit looks the same in git history, it's actually a new commit with a different Hash. – Sta_Doc Nov 30 '20 at 19:38
  • @Sta_Doc That is entirely right and is the very nature of the rebase, you will not get the same hashes. Whatever commits rebase produces, they will be entirely new. – Lasse V. Karlsen Nov 30 '20 at 21:19
  • 1
    @Sta_Doc Know that the parent commit is influencing the calculation of the hash of a commit, so if you "move" or "copy" a commit to sit on top of a different parent, its hash will change, even though everything else is identical. – Lasse V. Karlsen Nov 30 '20 at 21:21
  • Very true! I included several older commits (say, commit D, E) during interactive rebasing commit A, B, C and soon found out D, E ended up with new Hash. I included them simply wanted to make sure I'm not missing any commits to rebase. This is a valuable lesson that when doing interactive rebase, just include those commits we need to change. – Sta_Doc Dec 01 '20 at 06:41
3

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 )

user983447
  • 1,598
  • 4
  • 19
  • 36
2

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.

Melebius
  • 6,183
  • 4
  • 39
  • 52
0

Pick is used to include commits.

By default, you are given a table of contents of the commits you selected to rebase. The table of contents is sorted in ascending order by date. Rearranging the order of the pick command changes the order of the commits when you start rebase.

이경언
  • 156
  • 1
  • 11
0

It just uses the commit as it is - that is, no modifications will be made to it.

pick (p for short) is the default action. In this case it would reapply the commit as is, no changes in its contents or message

nj2237
  • 1,220
  • 3
  • 21
  • 25