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

[Bug?] MERGE_HEAD lost with git checkout master

From
Chris Packham <judge.packham@gmail.com>
Date
Sep 4, 2013, 06:17 UTC
Message-ID
<CAFOYHZD0reLWt-wYrcKy=LVKD3q0uJjgVLVYSAzU+zWMgtWguQ@mail.gmail.com>
Hi,

At $dayjob we have some simple "code quality" checks that we run to make sure that things are heading in the right direction. These are usually run as part of our automated builds but people occasionally run them when merging updates from other teams or preparing to merge to the integration branch.

The typical invocation is something like
  git checkout HEAD^
  score1=$(script.sh)
  git checkout master
  score2=$(script.sh)
  # compare scores ...

The problem is that if this is run after resolving merge conflicts but before committing the changes (i.e. the merge resolution is in the index) the fact that a merge was in progress is lost. I have modified script.sh to check for a clean work tree but I'm wondering if this is actually a bug worth fixing.

Here's a simple reproduction (apologies in advance for gmails wrapping)
  $ git --version
  git version 1.8.4.rc2
  $ git init
  $ for x in a b c d e f; do echo "$x" >"${x}.txt"; git add
"${x}.txt"; git commit -m"Add ${x}.txt"; done
  $ git checkout -b foo HEAD^^^
  $ for x in d e f; do echo "x" >"${x}.txt"; git add "${x}.txt"; git
commit -m"Add ${x}.txt"; done
  $ git checkout master
  $ git merge foo
  $ git mergetool
  # At this point the conflict resolution is in the index as expected
  $ git checkout HEAD^
  error: Your local changes to the following files would be
overwritten by checkout:
        f.txt
  Please, commit your changes or stash them before you can switch branches.
  Aborting
  # OK so far so good. Checkout failed and we're still in a mergey state
  $ ll .git
  drwxr-xr-x  2 chrisp swdept 4096 Sep  4 17:47 info/
  drwxr-xr-x  3 chrisp swdept 4096 Sep  4 17:49 logs/
  -rw-r--r--  1 chrisp swdept   41 Sep  4 17:51 MERGE_HEAD
  -rw-r--r--  1 chrisp swdept    0 Sep  4 17:51 MERGE_MODE
  -rw-r--r--  1 chrisp swdept   52 Sep  4 17:51 MERGE_MSG
  -rw-r--r--  1 chrisp swdept  141 Sep  4 17:51 MERGE_RR
  drwxr-xr-x 40 chrisp swdept 4096 Sep  4 17:52 objects/
  -rw-r--r--  1 chrisp swdept   41 Sep  4 17:51 ORIG_HEAD
  $ git checkout master
  M       d.txt
  M       e.txt
  M       f.txt
  Already on 'master'
  # Hmm, that kind of indicates that it did something but "Already on
'master'" makes me think it was a noop
  $ ll .git
  drwxr-xr-x  2 chrisp swdept 4096 Sep  4 17:47 info/
  drwxr-xr-x  3 chrisp swdept 4096 Sep  4 17:49 logs/
  drwxr-xr-x 40 chrisp swdept 4096 Sep  4 17:52 objects/
  -rw-r--r--  1 chrisp swdept   41 Sep  4 17:51 ORIG_HEAD
  # mergey state is lost but the changes are still in the index.

Cheers, Chris

Message 1 of 1 in “[Bug?] MERGE_HEAD lost with git checkout master”
  1. Chris PackhamSep 4, 2013

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.