{"thread":{"id":"34846","subject":"[Bug?] MERGE_HEAD lost with git checkout master","startedAt":"2013-09-04T06:17:26Z","lastAt":"2013-09-04T06:17:26Z","messageCount":1,"participants":["Chris Packham"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"226699","messageId":"CAFOYHZD0reLWt-wYrcKy=LVKD3q0uJjgVLVYSAzU+zWMgtWguQ@mail.gmail.com","threadId":"34846","inReplyTo":null,"subject":"[Bug?] MERGE_HEAD lost with git checkout master","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2013-09-04T06:17:26Z","receivedAt":"2013-09-04T06:17:26Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"Hi,\n\nAt $dayjob we have some simple \"code quality\" checks that we run to\nmake sure that things are heading in the right direction. These are\nusually run as part of our automated builds but people occasionally\nrun them when merging updates from other teams or preparing to merge\nto the integration branch.\n\nThe typical invocation is something like\n  git checkout HEAD^\n  score1=$(script.sh)\n  git checkout master\n  score2=$(script.sh)\n  # compare scores ...\n\nThe problem is that if this is run after resolving merge conflicts but\nbefore committing the changes (i.e. the merge resolution is in the\nindex) the fact that a merge was in progress is lost. I have modified\nscript.sh to check for a clean work tree but I'm wondering if this is\nactually a bug worth fixing.\n\nHere's a simple reproduction (apologies in advance for gmails wrapping)\n\n  $ git --version\n  git version 1.8.4.rc2\n  $ git init\n  $ for x in a b c d e f; do echo \"$x\" >\"${x}.txt\"; git add\n\"${x}.txt\"; git commit -m\"Add ${x}.txt\"; done\n  $ git checkout -b foo HEAD^^^\n  $ for x in d e f; do echo \"x\" >\"${x}.txt\"; git add \"${x}.txt\"; git\ncommit -m\"Add ${x}.txt\"; done\n  $ git checkout master\n  $ git merge foo\n  $ git mergetool\n\n  # At this point the conflict resolution is in the index as expected\n\n  $ git checkout HEAD^\n  error: Your local changes to the following files would be\noverwritten by checkout:\n        f.txt\n  Please, commit your changes or stash them before you can switch branches.\n  Aborting\n\n  # OK so far so good. Checkout failed and we're still in a mergey state\n\n  $ ll .git\n  drwxr-xr-x  2 chrisp swdept 4096 Sep  4 17:47 info/\n  drwxr-xr-x  3 chrisp swdept 4096 Sep  4 17:49 logs/\n  -rw-r--r--  1 chrisp swdept   41 Sep  4 17:51 MERGE_HEAD\n  -rw-r--r--  1 chrisp swdept    0 Sep  4 17:51 MERGE_MODE\n  -rw-r--r--  1 chrisp swdept   52 Sep  4 17:51 MERGE_MSG\n  -rw-r--r--  1 chrisp swdept  141 Sep  4 17:51 MERGE_RR\n  drwxr-xr-x 40 chrisp swdept 4096 Sep  4 17:52 objects/\n  -rw-r--r--  1 chrisp swdept   41 Sep  4 17:51 ORIG_HEAD\n\n  $ git checkout master\n  M       d.txt\n  M       e.txt\n  M       f.txt\n  Already on 'master'\n\n  # Hmm, that kind of indicates that it did something but \"Already on\n'master'\" makes me think it was a noop\n\n  $ ll .git\n  drwxr-xr-x  2 chrisp swdept 4096 Sep  4 17:47 info/\n  drwxr-xr-x  3 chrisp swdept 4096 Sep  4 17:49 logs/\n  drwxr-xr-x 40 chrisp swdept 4096 Sep  4 17:52 objects/\n  -rw-r--r--  1 chrisp swdept   41 Sep  4 17:51 ORIG_HEAD\n\n  # mergey state is lost but the changes are still in the index.\n\nCheers,\nChris\n"}]}