{"thread":{"id":"25778","subject":"[BUG?] git checkout -b removes MERGE_HEAD","startedAt":"2010-11-18T07:15:23Z","lastAt":"2010-11-18T19:26:47Z","messageCount":4,"participants":["Jan Hudec","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"156084","messageId":"456aec650e66bba518b8a5ec88c88a6b.squirrel@artax.karlin.mff.cuni.cz","threadId":"25778","inReplyTo":null,"subject":"[BUG?] git checkout -b removes MERGE_HEAD","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2010-11-18T07:15:23Z","receivedAt":"2010-11-18T07:15:23Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"Hello all,\n\nI am not sure whether it is a bug or not, but it definitely did\nsurprise me a lot. The use-case was as follows:\n\n - I checked out master and ran a merge from branch (let's call\n   it \"branch\"). It had a lot of conflicts, so I needed to test\n   the result well.\n - During the testing I found a problem, but it may have already\n   existed on master before the merge.\n - Therefore I needed to return to clean master, test it and return\n   to the merge. So I thought I'd commit the merge to a temporary\n   branch, test master again and merge the temporary to master if\n   the problem is not from the merge. So I did:\n\n   $ git checkout -b temp\n   $ git commit\n\n   OOPS! It forgot it was a merge.\n\nYes, I could have simply commited to master and reset --hard it\nback. But I didn't expect it to forget it was a merge in the first\nplace. After all, it does NOT touch the index nor the working tree,\nso why should it clear the MERGE_HEAD and MERGE_MSG?\n\nSo should this behaviour be changed?\n\nThanks,\nJan\n\n-- \n                                        - Jan Hudec <bulb@ucw.cz>\n"},{"id":"156129","messageId":"7vwroabhng.fsf@alter.siamese.dyndns.org","threadId":"25778","inReplyTo":"456aec650e66bba518b8a5ec88c88a6b.squirrel@artax.karlin.mff.cuni.cz","subject":"Re: [BUG?] git checkout -b removes MERGE_HEAD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-18T18:39:31Z","receivedAt":"2010-11-18T18:39:31Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Jan Hudec\" <bulb@ucw.cz> writes:\n\n>  - During the testing I found a problem, but it may have already\n>    existed on master before the merge.\n>  - Therefore I needed to return to clean master, test it and return\n>    to the merge. So I thought I'd commit the merge to a temporary\n>    branch, test master again and merge the temporary to master if\n>    the problem is not from the merge. So I did:\n>\n>    $ git checkout -b temp\n>    $ git commit\n>\n>    OOPS! It forgot it was a merge.\n\nI think it was an oversight by the author of 91dcdfd (Make \"git checkout\"\ncreate new branches on demand, 2005-07-11) who forgot that he also did\nef0bfa2 (Remove MERGE_HEAD in \"git checkout/reset\", 2005-06-21).  The\nrationale for the removal of MERGE_HEAD from the earlier commit is:\n\n    [this command] will end up resetting the index to some specific\n    head, and any unresolved merge will be forgotten [hence there is no\n    point recording the result as a merge].\n\nbut when used with -b no such \"resetting of the index\" happens.\n\nHaving said that, changing it not to remove MERGE_HEAD and MERGE_MSG is\nprobably not sufficient, as MERGE_MSG would likely to already record to\nwhich branch you are recording the merge (I didn't check, though).\n"},{"id":"156132","messageId":"20101118190101.GP3693@efreet.light.src","threadId":"25778","inReplyTo":"7vwroabhng.fsf@alter.siamese.dyndns.org","subject":"Re: [BUG?] git checkout -b removes MERGE_HEAD","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2010-11-18T19:01:01Z","receivedAt":"2010-11-18T19:01:01Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Thu, Nov 18, 2010 at 10:39:31 -0800, Junio C Hamano wrote:\n> \"Jan Hudec\" <bulb@ucw.cz> writes:\n> \n> >  So I did:\n> >\n> >    $ git checkout -b temp\n> >    $ git commit\n> >\n> >    OOPS! It forgot it was a merge.\n> \n> I think it was an oversight by the author of 91dcdfd (Make \"git checkout\"\n> create new branches on demand, 2005-07-11) who forgot that he also did\n> ef0bfa2 (Remove MERGE_HEAD in \"git checkout/reset\", 2005-06-21).  The\n> rationale for the removal of MERGE_HEAD from the earlier commit is:\n> \n>     [this command] will end up resetting the index to some specific\n>     head, and any unresolved merge will be forgotten [hence there is no\n>     point recording the result as a merge].\n> \n> but when used with -b no such \"resetting of the index\" happens.\n> \n> Having said that, changing it not to remove MERGE_HEAD and MERGE_MSG is\n> probably not sufficient, as MERGE_MSG would likely to already record to\n> which branch you are recording the merge (I didn't check, though).\n\nI believe it indeed does. However since it's now just a template for the\ncommit message, it can be fixed up by the user. If he actually wants to, that\nis.\n\nIn my case, I only needed to stash the changes, so I could switch back to\n'master' (left merge parent) to test the bug I was seeing was already there\nand than I merged the temporary branch to 'master' (which was fast forward).\nSo the message saying I merged to 'master' was actually appropriate even when\nI was commiting to some other ref.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"156135","messageId":"20101118192647.GD30438@sigill.intra.peff.net","threadId":"25778","inReplyTo":"7vwroabhng.fsf@alter.siamese.dyndns.org","subject":"Re: [BUG?] git checkout -b removes MERGE_HEAD","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-11-18T19:26:47Z","receivedAt":"2010-11-18T19:26:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Nov 18, 2010 at 10:39:31AM -0800, Junio C Hamano wrote:\n\n> I think it was an oversight by the author of 91dcdfd (Make \"git checkout\"\n> create new branches on demand, 2005-07-11) who forgot that he also did\n> ef0bfa2 (Remove MERGE_HEAD in \"git checkout/reset\", 2005-06-21).  The\n> rationale for the removal of MERGE_HEAD from the earlier commit is:\n> \n>     [this command] will end up resetting the index to some specific\n>     head, and any unresolved merge will be forgotten [hence there is no\n>     point recording the result as a merge].\n> \n> but when used with -b no such \"resetting of the index\" happens.\n\nIt is not necessarily about \"-b\" is it? It is about moving to a\ndifferent commit. So I would think that on branch \"master\":\n\n  # should clear MERGE_HEAD\n  git checkout foo\n\n  # should not clear MERGE_HEAD; it's a no-op, and we have in the past\n  # encouraged people to run this to see the ahead/behind count\n  git checkout\n  # or\n  git checkout master\n\n  # should clear MERGE_HEAD; we are moving to a new commit\n  git checkout -b foo some_commit\n\n  # should not clear MERGE_HEAD; this is Jan's case\n  git checkout -b foo\n  # or\n  git checkout -b foo master\n\n-Peff\n"}]}