5

I am doing merge bunches of commits using cherry-pick

git rev-list --reverse something-begin..something-end | git cherry-pick --stdin

and then ends up with error message

...
You are currently cherry-picking commit xxxyyy.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

If you wish to skip this commit, use:

    git reset

Then "git cherry-pick --continue" will resume cherry-picking the remaining commits.

I dont want to pick any of these empty commits.

It is very annoying that entering git reset; git cherry-pick --continue for each stop and prompts.

why didn't it provide a --skip-empty option? And then I got to this thread:

http://markmail.org/message/yowzaetyu32ulvz7

It's so bad that I check my git version 2.9.3 and even found it cherry-pick do not supports either --skip-empty or --empty-commpit=skip or any other.

I had check that git rev-list has an option --remove-empty but it just did not work any help.

William Leung
  • 1,556
  • 17
  • 26

2 Answers2

3

Finally I found the solution.

git rev-list --reverse something-begin..something-end . | git cherry-pick --stdin

Adding a dot to rev-list command (that is the path parts) will skip all empty commits for me (what is --remove-empty for??)

William Leung
  • 1,556
  • 17
  • 26
  • As the documentation says, `--remove-empty` means "Stop when a given path disappears from the tree." That is, stop looking at earlier revisions entirely. – torek Dec 06 '16 at 07:01
  • @torek Yes I had read that line, and I had confirmed that is not what I want. but that document line `Stop when a given path disappears from the tree` is not clear enough I just dont catch what it means. – William Leung Dec 06 '16 at 08:26
  • Well, consider what `git rev-list` does if you just give it one single commit. It prints that commit's ID, and then that commit's parent's ID, and then that parent's parent ID, and then *that* parent's parent, and another and another and so on. When does it *stop* following from parent to parent? The usual answer is: when there are no more parents. But you can make it stop earlier. – torek Dec 06 '16 at 08:43
  • Did you try `git cherry-pick something-begin..something-end` or was that not available at the time? Does it have the same problem? – Dan M. Jan 24 '19 at 13:05
1

You can use rebase in this way (having your target branch checked out):

git reset --hard something-end && git rebase ORIG_HEAD

which automatically skips redundant commits.

Credits go to my colleague Michael Adam, who came up with that idea.

ansiwen
  • 1,061
  • 8
  • 13
  • 1
    rebase do not work with subtree rebasing. Actually I am using cherry-pick -Xsubtree option to pick set of commits from one repository to an other witch only includes a folder of origin – William Leung Nov 26 '18 at 07:19