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

[BUG] multi-commit cherry-pick messes up the order of commits

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Jan 11, 2012, 17:31 UTC
Message-ID
<20120111173101.GQ30469@goldbirke>
Hi,

I did some multi-commit cherry-picks lately, and noticed that sometimes cherry-pick applied the commits in different order than I specified on the command line. After some debugging, today I could finally come up with a receipe to reproduce:

  git init
  echo 1 >a && git add a
  git commit -m a
  echo 2 >b && git add b
  git commit -m b
  sleep 2 && echo 3 >c && git add c
  git commit -m c
  git checkout -b branch HEAD^^
  git cherry-pick master master^    # the later commit first
where the 'git cherry-pick' command produces the following output:
[branch ef5b86e0] b
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 b
[branch 6a74f934] c
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 c

Notice that master^, i.e. the commit adding the file 'b', is picked before master, i.e. the commit adding 'c', although the order on the command line was the reverse.

This is because
  cmd_cherry_pick()
    pick_revisions()
      walk_revs_populate_todo()
        prepare_revs()

calls prepare_revision_walk(), which parses the commits from the command line in the order they were specified, but inserts them into a list ordered by date, and commits will be picked in the order they appear in this list. So if you specify commits in a different order than their committer date or commits with the same commiter date (which are often produced by am, rebase, and multi-commit cherry-pick), then they will be picked in wrong order.

As far as I can tell, this buggy behavior is as old as multi-commit cherry-pick itself, i.e. 7e2bfd3f (revert: allow cherry-picking more than one commit, 2010-06-02).

Best, Gábor

Next: Christian Couder
Message 1 of 24 in “[BUG] multi-commit cherry-pick messes up the order of commits”
  1. SZEDER GáborJan 11, 2012
  2. Christian CouderJan 12, 2012
  3. SZEDER GáborJan 12, 2012
  4. Ramkumar RamachandraJan 12, 2012
  5. Jeff KingJan 12, 2012
  6. Ramkumar RamachandraJan 12, 2012
  7. Ramkumar RamachandraJan 12, 2012
  8. Jeff KingJan 12, 2012
  9. Ramkumar RamachandraJan 12, 2012
  10. cherry-pick: add failing test for out-of-order pickRamkumar Ramachandra, Jan 12, 2012
  11. Jonathan NiederJan 12, 2012
  12. cherry-pick: add failing test for out-of-order pickRamkumar Ramachandra, Jan 12, 2012
  13. Jonathan NiederJan 12, 2012
  14. Junio C HamanoJan 12, 2012
  15. Ramkumar RamachandraJan 12, 2012
  16. Jeff KingJan 12, 2012
  17. Jonathan NiederJan 12, 2012
  18. Jeff KingJan 12, 2012
  19. Junio C HamanoJan 12, 2012
  20. Johannes SixtJan 12, 2012
  21. Ramkumar RamachandraJan 12, 2012
  22. Jonathan NiederJan 12, 2012
  23. Jonathan NiederJan 12, 2012
  24. Junio C HamanoJan 12, 2012

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.