git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: error: Can't cherry-pick into empty head

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jun 6, 2016, 13:21 UTC
Message-ID
<afafa51c-f950-594e-7142-5b28b1182add@drmicha.warpmail.net>
In-Reply-To
<CAOxYW4yTCMYcY=9YvwHNK5rKDK0_f-Uc7L92-QuQkv_hwCV+HA@mail.gmail.com>
Fabrizio Cucci venit, vidit, dixit 28.05.2016 19:54:
Show 40 quoted lines
> Hello everyone,
> 
> I'm trying to understand why I'm getting the error as per subject.
> 
> The scenario is the following: I'm on the master branch (which
> contains several commits) and I would like to create a new empty
> branch (let's call it new-orphan) and cherry-pick only the commits
> related to a specific folder (let's call it my-folder) from the master
> branch.
> 
> So, I tried the following command sequence:
> 
>   master $ git checkout --orphan new-orphan
>   new-orphan $ git rm --cached -r .
>   new-orphan $ git clean -df
> 
> After confirming that I'm in a clean state (with "$ git status") I tried:
> 
>   new-orphan $ git rev-list --reverse master -- my-folder/ | git
> cherry-pick --stdin
> 
> as suggested https://git-scm.com/docs/git-cherry-pick, but what I get
> is "error: Can't cherry-pick into empty head".
> 
> What I don't really understand is:
> 
> 1) if I cherry-pick a single commit instead of multiple commits,
> everything works fine:
> 
>   new-orphan $ git cherry-pick <some-commit-id>
> 
> 2) if I commit something before trying the above command, everything works fine:
> 
>   new-orphan $ touch README
>   new-orphan $ git add README
>   new-orphan $ git commit -m "added README"
>   new-orphan $ git rev-list --reverse master -- my-folder/ | git
> cherry-pick --stdin
> 
> Can someone please help me understand this?

The implementation for the single commit and multiple commit cases is different (so that you can do a single cherry-pick from with a running cherry-pick sequence). As a side effect, the single commit pick does not care about an empty head.

I'll follow up with a patch which changes that.
Michael
Previous: Fabrizio CucciNext: Michael J Gruber
Message 2 of 7 in “error: Can't cherry-pick into empty head”
  1. Fabrizio CucciMay 28, 2016
  2. Michael J GruberJun 6, 2016
  3. cherry-pick: allow to pick to unborn branchesMichael J Gruber, Jun 6, 2016
  4. Torsten BögershausenJun 6, 2016
  5. Junio C HamanoJun 6, 2016
  6. Michael J GruberJun 7, 2016
  7. Junio C HamanoJun 7, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.