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

Re: [RFH] git cherry-pick takes forever

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 10, 2008, 10:00 UTC
Message-ID
<7vk5dkxqvf.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080910082610.GA3144@mageo.cz>
Michal Vitecek <fuf@mageo.cz> writes:
Show 8 quoted lines
>  Hello everyone,
>
>  I have two git repositories: one is the origin of the other. However no
>  merging is being done as the projects in the repositories quite differ
>  but still use the same core. So to propagate changes I cherry-pick
>  those which are useful from one repository to another.
>
>  however 'git cherry-pick' has lately started to last almost forever:

Can you define "lately"? Is it a function of your git version, or is it a function of the age of your repositories?

Show 8 quoted lines
>  $ time git cherry-pick b42b77e66a83f1298d9900a9bb1078b9b42e8618
>  Finished one cherry-pick.
>  Created commit 7caef83: - removed some superfluous newlines
>  2 files changed, 0 insertions(+), 2 deletions(-)
>  git cherry-pick b42b77e66a83f1298d9900a9bb1078b9b42e8618  282.97s user 34.69s system 100% cpu 5:17.63 total
>
>  Both repositories have approximately 16k commits and their forking
>  point (merge base) is 250 to 490 commits far away.

When talking about cherry-pick, the size of the history (unless the repository has too many objects and badly packed) does not matter; the operation is purely about your current state, the cherry-picked commit itself, and the parent commit of the cherry-picked one.

Taking 5 minutes to cherry-pick a change to only two paths, one line deletion each, is plain ridiculous, but if the tree state of cherry-picked commit and the tree state of the target is vastly different (e.g. almost no common pathnames), the behaviour is certainly understandable. Ancient git used straight three-way merge for cherry-pick, but recent ones use more expensive "recursive-merge", which tries to detect renames. If the states of trees are very dissimilar, you can end up wasting a lot of time.

    $ H=$(git rev-parse 7caef83^) ;# the commit before cherry-pick
    $ C=b42b77e6 ;# the cherry-picked one
cherry-pick operation roughly runs these two diffs:
    $ time git diff --shortstat -M $H $C
    $ time git diff --shortstat -M $H $C^1
and uses the result to perform its work.  Can you clock these?

If you rarely have renames, it may be much more efficient to run "git format-patch -1 --stdout $C | git am -3" instead of cherry-pick.

Previous: Michal VitecekNext: Michal Vitecek
Message 2 of 3 in “[RFH] git cherry-pick takes forever”
  1. Michal VitecekSep 10, 2008
  2. Junio C HamanoSep 10, 2008
  3. Michal VitecekSep 11, 2008

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.