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

cherry-picking a commit clobbers a file which is a directory in the target commit

From
NNick <oinksocket@letterboxes.org>
Date
Sep 2, 2010, 16:17 UTC
Message-ID
<4C7FCE27.7000500@letterboxes.org>
This was seen on git version 1.7.0.4 on Ubuntu Lucid.

Basically, cherry-picking a commit from a branch where a file in the current branch has been replaced by a directory, git clobbers the file and the cherry-pick fails reporting conflicts.

To replicate:
   $ mkdir clobber
   $ cd clobber/
   $ git init
   $ touch sausage
   $ git add sausage
   $ git commit -m "added sausage"
   $ git checkout -b branch1
   $ mv sausage sausage1
   $ mkdir sausage
   $ mv sausage1 sausage/roll
   $ git add sausage/roll
   $ git commit -m "renamed sausage as sausage/roll"
   $ touch falafel
   $ git add falafel
   $ git commit -m "added falafel"
   $ git checkout master
Now if you try to cherry pick the commit just added to branch1 onto master:
    $ git cherry-pick branch1
    Automatic cherry-pick failed.  After resolving the conflicts,
    mark the corrected paths with 'git add <paths>' or 'git rm <paths>'
    and commit the result with:
            git commit -c branch1
    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       renamed:    sausage -> falafel
    #
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #       sausage~HEAD

Not what I expected at all. I'd not expect the file 'sausage' to be modified, just the new file 'falafel' added, as I did in the original commit.

I know I can recover from this by moving sausage~HEAD back to sausage, or delete it and check out sausage again, but I suspect it just shouldn't happen at all.

Is this a bug?
N
Next: Nick
Message 1 of 14 in “cherry-picking a commit clobbers a file which is a directory in the target commit”
  1. NickSep 2, 2010
  2. NickSep 6, 2010
  3. Elijah NewrenSep 6, 2010
  4. 0/3 Fix resolvable rename + D/F conflict testcasesElijah Newren, Sep 6, 2010
  5. Elijah NewrenSep 6, 2010
  6. 1/3 t3509: Add rename + D/F conflict testcases that recursive strategy failsElijah Newren, Sep 6, 2010
  7. 2/3 merge-recursive: Small code cleanupElijah Newren, Sep 6, 2010
  8. Elijah NewrenSep 6, 2010
  9. Junio C HamanoSep 6, 2010
  10. Schalk, KenSep 7, 2010
  11. Elijah NewrenSep 8, 2010
  12. Schalk, KenSep 9, 2010
  13. Camille MoncelierOct 21, 2010
  14. 3/3 merge-recursive: D/F conflicts where was_a_dir/file -> was_a_dirElijah Newren, Sep 6, 2010

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.