{"thread":{"id":"20938","subject":"could not detach HEAD error didn't identify the cause of the issue","startedAt":"2009-09-14T00:14:24Z","lastAt":"2009-09-14T22:39:41Z","messageCount":4,"participants":["Ben Bradshaw","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"123126","messageId":"4AAD8AE0.9070305@catalyst.net.nz","threadId":"20938","inReplyTo":null,"subject":"could not detach HEAD error didn't identify the cause of the issue","fromName":"Ben Bradshaw","fromEmail":"ben@catalyst.net.nz","sentAt":"2009-09-14T00:14:24Z","receivedAt":"2009-09-14T00:14:24Z","isPatch":false,"sender":{"key":"ben@catalyst.net.nz","avatar":null},"body":"Hi,\n\nI was asked to post this issue to the list, I've just had git tell me it\ncan't detach HEAD which left me scratching mine as to the cause and fix.\nTurns out if I have local untracked files that the remote branch also\nhas then this error will trigger. I have included my shell backlog\n(client data removed). In this example the site_map folder was present\non master and I had a local, untracked copy.\n\ngit can obviosly detect this issue and stop my local copy getting in a\nbad state, but an error message such as \"sites/all/modules/site_map/ is\npresent in HEAD but is untracked locally, unable to apply changes\" (or\nsomething to point the finger) would be much appreciated.\n\nben@carbon:redacted/$ git pull --rebase\nremote: Counting objects: 91, done.\nremote: Compressing objects: 100% (72/72), done.\nremote: Total 74 (delta 27), reused 0 (delta 0)\nUnpacking objects: 100% (74/74), done.\nFrom git+ssh://redacted\n   fb1a4c9..bf06bbd  master     -> origin/master\nFirst, rewinding head to replay your work on top of it...\nFast-forwarded master to bf06bbd9e50a2732164fba9e60e65606ab1267ab.\nben@carbon:redacted/$ pwd\n/home/ben/redacted\nben@carbon:redacted/$ git pull --rebase\nFirst, rewinding head to replay your work on top of it...\ncould not detach HEAD\nben@carbon:redacted/$ git status\n# On branch master\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#    sites/all/modules/jquery.ui-1.6.zip\n#    sites/all/modules/jquery_ui-6.x-1.3.tar.gz\n#    sites/all/modules/jquery_ui/\n#    sites/all/modules/modalframe-6.x-1.3.tar.gz\n#    sites/all/modules/modalframe/\n#    sites/all/modules/nodereference_explorer-6.x-1.1-beta6.tar.gz\n#    sites/all/modules/nodereference_explorer/\n#    sites/all/modules/noderelationships-6.x-1.1.tar.gz\n#    sites/all/modules/noderelationships/\n#    sites/all/modules/site_map-6.x-1.1.tar.gz\n#    sites/all/modules/site_map/\nnothing added to commit but untracked files present (use \"git add\" to track)\nben@carbon:redacted/$ rm -rf sites/all/modules/site_map/\nben@carbon:redacted/$ git status\n# On branch master\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#    sites/all/modules/jquery.ui-1.6.zip\n#    sites/all/modules/jquery_ui-6.x-1.3.tar.gz\n#    sites/all/modules/jquery_ui/\n#    sites/all/modules/modalframe-6.x-1.3.tar.gz\n#    sites/all/modules/modalframe/\n#    sites/all/modules/nodereference_explorer-6.x-1.1-beta6.tar.gz\n#    sites/all/modules/nodereference_explorer/\n#    sites/all/modules/noderelationships-6.x-1.1.tar.gz\n#    sites/all/modules/noderelationships/\n#    sites/all/modules/site_map-6.x-1.1.tar.gz\nnothing added to commit but untracked files present (use \"git add\" to track)\nben@carbon:redacted/$ git pull --rebase\nFirst, rewinding head to replay your work on top of it...\nFast-forwarded master to 527afccc7565929baf7890b42b1a34174014fee7.\n\n\nThanks for your time (and git)\nBen\n"},{"id":"123141","messageId":"20090914112211.GC9216@sigill.intra.peff.net","threadId":"20938","inReplyTo":"4AAD8AE0.9070305@catalyst.net.nz","subject":"Re: could not detach HEAD error didn't identify the cause of the issue","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-09-14T11:22:11Z","receivedAt":"2009-09-14T11:22:11Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Sep 14, 2009 at 12:14:24PM +1200, Ben Bradshaw wrote:\n\n> I was asked to post this issue to the list, I've just had git tell me it\n> can't detach HEAD which left me scratching mine as to the cause and fix.\n> Turns out if I have local untracked files that the remote branch also\n> has then this error will trigger. I have included my shell backlog\n> (client data removed). In this example the site_map folder was present\n> on master and I had a local, untracked copy.\n> \n> git can obviosly detect this issue and stop my local copy getting in a\n> bad state, but an error message such as \"sites/all/modules/site_map/ is\n> present in HEAD but is untracked locally, unable to apply changes\" (or\n> something to point the finger) would be much appreciated.\n\nI couldn't reproduce it here; I get such a message.\n\n  # set up forked repo, \"another\" exists only on master\n  $ mkdir repo && cd repo\n  $ git init\n  $ echo content >file && git add file && git commit -m base\n  $ echo content >another && git add another && git commit -m another\n  $ git checkout -b other HEAD^\n  $ echo changes >file && git commit -a -m changes\n\n  # add untracked \"another\" here\n  $ echo untracked >another\n\n  # try rebase\n  $ git rebase master\n  First, rewinding head to replay your work on top of it...\n  error: Untracked working tree file 'another' would be overwritten by merge.\n  could not detach HEAD\n\n  # try git pull --rebase, in case it hides the message\n  $ git config branch.other.remote .\n  $ git config branch.other.merge refs/heads/master\n  $ git pull --rebase\n  From .\n   * branch            master     -> FETCH_HEAD\n  First, rewinding head to replay your work on top of it...\n  error: Untracked working tree file 'another' would be overwritten by merge.\n  could not detach HEAD\n\nI'll admit the \"could not detach HEAD\" message would probably be better as:\n\n  rebase: unable to move HEAD to 'master', aborting rebase\n\nor something similar.\n\nWhat version of git are you using? What does my test case above produce\nfor you?\n\n-Peff\n"},{"id":"123193","messageId":"4AAEAF28.2050604@catalyst.net.nz","threadId":"20938","inReplyTo":"4AAEAE15.7050607@catalyst.net.nz","subject":"Re: could not detach HEAD error didn't identify the cause of the issue","fromName":"Ben Bradshaw","fromEmail":"ben@catalyst.net.nz","sentAt":"2009-09-14T21:01:28Z","receivedAt":"2009-09-14T21:01:28Z","isPatch":false,"sender":{"key":"ben@catalyst.net.nz","avatar":null},"body":"Hi Jeff,\n\nI'm using git version 1.5.6.5 - I think I can elaborate on the issue\nsome more though. I'll step through the process that got me to the point\nof failure. For the purposes of this example 'ben@carbon' is me at my\nlocal machine, 'ben@staging' is our staging server. Our development\nsetup for this project has us all working on the staging server except\nwhen we need to test something that we don't want on staging (could\nbreak things) so I also have a local copy of staging. (This seems\nbackwards to me but it's working rather well for the short time line we\nhave).\n\nIn this case I did the following:\n1. Add module site_map to carbon\n2. Install and test on carbon\n3. Add module site_map to staging\n4. Install and test on staging\n5. git commit && git push on staging\n6. git pull --rebase on carbon\n\nI think you will need two checkouts of your repo in order to trigger\nthis case?\n\nBen\n>\n> Jeff King wrote:\n>> On Mon, Sep 14, 2009 at 12:14:24PM +1200, Ben Bradshaw wrote:\n>>\n>>   \n>>> I was asked to post this issue to the list, I've just had git tell me it\n>>> can't detach HEAD which left me scratching mine as to the cause and fix.\n>>> Turns out if I have local untracked files that the remote branch also\n>>> has then this error will trigger. I have included my shell backlog\n>>> (client data removed). In this example the site_map folder was present\n>>> on master and I had a local, untracked copy.\n>>>\n>>> git can obviosly detect this issue and stop my local copy getting in a\n>>> bad state, but an error message such as \"sites/all/modules/site_map/ is\n>>> present in HEAD but is untracked locally, unable to apply changes\" (or\n>>> something to point the finger) would be much appreciated.\n>>>     \n>>\n>> I couldn't reproduce it here; I get such a message.\n>>\n>>   # set up forked repo, \"another\" exists only on master\n>>   $ mkdir repo && cd repo\n>>   $ git init\n>>   $ echo content >file && git add file && git commit -m base\n>>   $ echo content >another && git add another && git commit -m another\n>>   $ git checkout -b other HEAD^\n>>   $ echo changes >file && git commit -a -m changes\n>>\n>>   # add untracked \"another\" here\n>>   $ echo untracked >another\n>>\n>>   # try rebase\n>>   $ git rebase master\n>>   First, rewinding head to replay your work on top of it...\n>>   error: Untracked working tree file 'another' would be overwritten by merge.\n>>   could not detach HEAD\n>>\n>>   # try git pull --rebase, in case it hides the message\n>>   $ git config branch.other.remote .\n>>   $ git config branch.other.merge refs/heads/master\n>>   $ git pull --rebase\n>>   From .\n>>    * branch            master     -> FETCH_HEAD\n>>   First, rewinding head to replay your work on top of it...\n>>   error: Untracked working tree file 'another' would be overwritten by merge.\n>>   could not detach HEAD\n>>\n>> I'll admit the \"could not detach HEAD\" message would probably be better as:\n>>\n>>   rebase: unable to move HEAD to 'master', aborting rebase\n>>\n>> or something similar.\n>>\n>> What version of git are you using? What does my test case above produce\n>> for you?\n>>\n>> -Peff\n>>\n>>   \n"},{"id":"123195","messageId":"20090914223941.GA20036@coredump.intra.peff.net","threadId":"20938","inReplyTo":"4AAEAF28.2050604@catalyst.net.nz","subject":"Re: could not detach HEAD error didn't identify the cause of the issue","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-09-14T22:39:41Z","receivedAt":"2009-09-14T22:39:41Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"[Please don't top-post; the usual etiquette on this list is to reply\nin-line].\n\nOn Tue, Sep 15, 2009 at 09:01:28AM +1200, Ben Bradshaw wrote:\n\n> I'm using git version 1.5.6.5 - I think I can elaborate on the issue\n> some more though. I'll step through the process that got me to the point\n> of failure.\n\nThanks for following up. I was able to reproduce your problem. The more\ncomplex setup you described is not necessary to reproduce (though thank\nyou for providing it, as it eliminated one possible source of\nvariation). It really is just about having an untracked file 'foo' in\nyour working tree, and the thing you are trying to rebase on top of also\nhas 'foo' as a tracked file.\n\nThe good news is that it has already been fixed. I bisected it down to:\n\n  commit 324c2c3177ca5b62b12029ce8821542fc29a2733\n  Author: Junio C Hamano <gitster@pobox.com>\n  Date:   Mon Jul 14 14:05:35 2008 -0700\n\n      git-rebase: report checkout failure\n\n      When detaching the HEAD to the base commit, the \"git checkout\"\n      command could fail if, for example, upstream contains a file that\n      would overrwrite a local, untracked file.  Unconditionally\n      discarding the standard error stream was done to squelch the\n      progress and notices back when checkout did not have -q option,\n      but there is no reason to keep doing it anymore.\n\n      Noticed by Robert Shearman.\n\nwhich sounds about right. :)\n\nIt made it into git v1.6.0, but not into any of the v1.5.x maintenance\nseries. I would suggest upgrading if you can.\n\n-Peff\n"}]}