{"thread":{"id":"24272","subject":"\"recursive\" merge strategy fails when renaming a file into a subdirectory: fatal: git write-tree failed to write a tree","startedAt":"2010-07-02T21:03:05Z","lastAt":"2010-07-02T21:03:05Z","messageCount":1,"participants":["Marcel Cary"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"144720","messageId":"AANLkTilrcoBcTgDeooTEmlnZ7lmg4vL4_8U_k_QSCH8E@mail.gmail.com","threadId":"24272","inReplyTo":null,"subject":"\"recursive\" merge strategy fails when renaming a file into a subdirectory: fatal: git write-tree failed to write a tree","fromName":"Marcel Cary","fromEmail":"marcel@care2team.com","sentAt":"2010-07-02T21:03:05Z","receivedAt":"2010-07-02T21:03:05Z","isPatch":false,"sender":{"key":"marcel@care2team.com","avatar":null},"body":"When I merge with a branch that renames hi to hi/there, the\n\"recursive\" strategy fails with this error:\n\n    hi/there: unmerged (45b983be36b73c0788dc9cbcb76cbb80fc7bb057)\n    fatal: git write-tree failed to write a tree\n\nThe \"resolve\" strategy works; that is my work-around for now:\n\n    git merge -s resolve master\n\n\nHere's a transcript of a simple example anyone can use to replicate\nthe problem, with some commentary interspersed.  I see this behavior\non 1.6.3.3 on Linux and 1.7.1 on Mac.\n\n    ~/tmp$ mkdir test-repo\n    ~/tmp$ cd test-repo/\n    ~/tmp/test-repo$ git init\n    Initialized empty Git repository in /Users/marcel/tmp/test-repo/.git/\n    ~/tmp/test-repo|master$ echo hi > hi\n    ~/tmp/test-repo|master$ git add hi\n    ~/tmp/test-repo|master$ git commit -m hi\n    [master (root-commit) 635cab8] hi\n     1 files changed, 1 insertions(+), 0 deletions(-)\n     create mode 100644 hi\n    ~/tmp/test-repo|master$ git branch other-feature\n    ~/tmp/test-repo|master$ git rm hi\n    rm 'hi'\n    ~/tmp/test-repo|master$ mkdir hi\n    ~/tmp/test-repo|master$ echo hi > hi/there\n    ~/tmp/test-repo|master$ git add hi/there\n    ~/tmp/test-repo|master$ git commit -m 'hi there'\n    [master eee387a] hi there\n     1 files changed, 0 insertions(+), 0 deletions(-)\n     rename hi => hi/there (100%)\n    ~/tmp/test-repo|master$ git checkout other-feature\n    Switched to branch 'other-feature'\n    ~/tmp/test-repo|other-feature$ echo foo > foo\n    ~/tmp/test-repo|other-feature$ git add foo\n    gmarcel@marcel-carys-macbook:~/tmp/test-repo|other-feature$ git\ncommit -m 'foo'\n    [other-feature 5d7bd95] foo\n     1 files changed, 1 insertions(+), 0 deletions(-)\n     create mode 100644 foo\n    ~/tmp/test-repo|other-feature$ git merge master\n    hi/there: unmerged (45b983be36b73c0788dc9cbcb76cbb80fc7bb057)\n    fatal: git write-tree failed to write a tree\n\nThat was the error.  Now, I've seen long-past posts about this error\nmessage that suggested using the standard conflict resolution\nprocedure, so here goes... (but it will produce a commit which is not\nin fact a merge commit).\n\n    ~/tmp/test-repo|other-feature$ git status\n    # On branch other-feature\n    # Changes to be committed:\n    #   (use \"git reset HEAD <file>...\" to unstage)\n    #\n    #\tdeleted:    hi\n    #\n    # Unmerged paths:\n    #   (use \"git reset HEAD <file>...\" to unstage)\n    #   (use \"git add/rm <file>...\" as appropriate to mark resolution)\n    #\n    #\tadded by them:      hi/there\n    #\n    ~/tmp/test-repo|other-feature$ ls -l hi\n    ls: hi: No such file or directory\n    ~/tmp/test-repo|other-feature$ git checkout master -- hi/there\n    ~/tmp/test-repo|other-feature$ git status\n    # On branch other-feature\n    # Changes to be committed:\n    #   (use \"git reset HEAD <file>...\" to unstage)\n    #\n    #\trenamed:    hi -> hi/there\n    #\n    ~/tmp/test-repo|other-feature$ git commit\n    [other-feature ef1d221] merged\n     1 files changed, 0 insertions(+), 0 deletions(-)\n     rename hi => hi/there (100%)\n    ~/tmp/test-repo|other-feature$ git log -n 1\n    commit ef1d221d87f09b08fd705f55ede4870dd3df338b\n    Author: Marcel Cary <marcel@earth.care2.com>\n    Date:   Fri Jul 2 13:21:29 2010 -0700\n\n        merged\n\nOk, there was the commit I got from the standard resolution procedure.\n Note how there's no line \"Merge: 5d7bd95 eee387a\" ?  Normally such a\ncommit header would be shown if the commit really had two parents.  So\nthe standard resolution procedure failed.  If I were to try merging\nagain, instead of \"Already up-to-date\" it would fail again with a\nsimilar message.\n\nSo I'll try again with the work-around...\n\n    ~/tmp/test-repo|other-feature$ git reset --hard HEAD@{1}\n    HEAD is now at 5d7bd95 foo\n    ~/tmp/test-repo|other-feature$ git merge -s resolve master\n    Trying really trivial in-index merge...\n    error: Merge requires file-level merging\n    Nope.\n    Trying simple merge.\n    Simple merge failed, trying Automatic merge.\n    Adding hi/there\n    Merge made by resolve.\n     hi => hi/there |    0\n     1 files changed, 0 insertions(+), 0 deletions(-)\n     rename hi => hi/there (100%)\n    ~/tmp/test-repo|other-feature$ git --version\n    git version 1.7.1\n    ~/tmp/test-repo|other-feature$\n\nThe \"resolve\" strategy works great.  It would be nice if the\n\"recursive\" merge strategy could also handle such a case, so users\ndon't have to know to choose a special one for this case.  Git\ngenerally seems to handle this sort of repurposing of path names\npretty well, so perhaps this is an oversight.\n\nNote that simply changing a file to a directory is not enough; one of\nthe new files in the directory has to appear as an exact or fuzzy\nrename of the original file.\n\nI'm not volunteering to fix it;  when I first searched Google for the\nerror message there was no conclusion (that applied to me at least)\nabout (a) what class of conditions leads to the error, nor (b) how to\nresolve or work around the problem, I thought I'd share this remedy,\nfor what it's worth.\n\nHere are the two threads I found:\n\nhttp://osdir.com/ml/git/2009-03/msg00247.html\nhttp://git.661346.n2.nabble.com/fatal-error-when-merging-a-rename-td2664375.html\n\nAnd there was even an attempt to fix it, but no mention of the \"-s\nresolve\" work around:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/100859/\n\nMarcel\n"}]}