Skip to content

Instantly share code, notes, and snippets.

@mafernando
Last active July 6, 2016 16:37
Show Gist options
  • Save mafernando/d58c6fc2c9011f11c1c5 to your computer and use it in GitHub Desktop.
Save mafernando/d58c6fc2c9011f11c1c5 to your computer and use it in GitHub Desktop.
Useful Git Commands
@mafernando
Copy link
Author

The way a cherry-pick works is by taking the diff a changeset represents (the difference between the working tree at that point and the working tree of its parent), and applying it to your current branch.

So, if a commit has two or more parents, it also represents two or more diffs - which one should be applied?

You're trying to cherry pick fd9f578, which was a merge with two parents. So you need to tell the cherry-pick command which one against which the diff should be calculated, by using the -m option. For example, git cherry-pick -m 1 fd9f578 to use parent 1 as the base.

I can't say for sure for your particular situation, but using git merge instead of git cherry-pick is generally advisable. When you cherry-pick a merge commit, it collapses all the changes made in the parent you didn't specify to -m into that one commit. You lose all their history, and glom together all their diffs. Your call.

http://stackoverflow.com/questions/9229301/git-cherry-pick-says-38c74d-is-a-merge-but-no-m-option-was-given

@mafernando
Copy link
Author

320
down vote
accepted
Git 1.7.2 introduced the ability to cherrypick a range of commits. From the release notes:

git cherry-pick" learned to pick a range of commits (e.g. "cherry-pick A..B" and "cherry-pick --stdin"), so did "git revert"; these do not support the nicer sequencing control "rebase [-i]" has, though.
Including important comments (credits to respective authors)

Note 1: In the "cherry-pick A..B" form, A should be older than B. If they're the wrong order the command will silently fail. – damian

Note 2: Also, this will not cherry-pick A, but rather everything after A up to and including B. – J. B. Rainsberger

Note 3: To include A just type git cherry-pick A^..B – sschaef

http://stackoverflow.com/questions/1670970/how-to-cherry-pick-multiple-commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment