threads / discuss / 20938

could not detach HEAD error didn't identify the cause of the issue

Subject: could not detach HEAD error didn't identify the cause of the issue

## tl;dr

4 messages between Sep 14, 2009 and Sep 14, 2009.

replies: 3people: 2as markdown or json

Ben Bradshaw· Sep 14, 2009, 00:14 UTC · lore
Hi,

I was asked to post this issue to the list, I've just had git tell me it can't detach HEAD which left me scratching mine as to the cause and fix. Turns out if I have local untracked files that the remote branch also has then this error will trigger. I have included my shell backlog (client data removed). In this example the site_map folder was present on master and I had a local, untracked copy.

git can obviosly detect this issue and stop my local copy getting in a bad state, but an error message such as "sites/all/modules/site_map/ is present in HEAD but is untracked locally, unable to apply changes" (or something to point the finger) would be much appreciated.

ben@carbon:redacted/$ git pull --rebase
remote: Counting objects: 91, done.
remote: Compressing objects: 100% (72/72), done.
remote: Total 74 (delta 27), reused 0 (delta 0)
Unpacking objects: 100% (74/74), done.
From git+ssh://redacted
   fb1a4c9..bf06bbd  master     -> origin/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to bf06bbd9e50a2732164fba9e60e65606ab1267ab.
ben@carbon:redacted/$ pwd
/home/ben/redacted
ben@carbon:redacted/$ git pull --rebase
First, rewinding head to replay your work on top of it...
could not detach HEAD
ben@carbon:redacted/$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    sites/all/modules/jquery.ui-1.6.zip
#    sites/all/modules/jquery_ui-6.x-1.3.tar.gz
#    sites/all/modules/jquery_ui/
#    sites/all/modules/modalframe-6.x-1.3.tar.gz
#    sites/all/modules/modalframe/
#    sites/all/modules/nodereference_explorer-6.x-1.1-beta6.tar.gz
#    sites/all/modules/nodereference_explorer/
#    sites/all/modules/noderelationships-6.x-1.1.tar.gz
#    sites/all/modules/noderelationships/
#    sites/all/modules/site_map-6.x-1.1.tar.gz
#    sites/all/modules/site_map/
nothing added to commit but untracked files present (use "git add" to track)
ben@carbon:redacted/$ rm -rf sites/all/modules/site_map/
ben@carbon:redacted/$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#    sites/all/modules/jquery.ui-1.6.zip
#    sites/all/modules/jquery_ui-6.x-1.3.tar.gz
#    sites/all/modules/jquery_ui/
#    sites/all/modules/modalframe-6.x-1.3.tar.gz
#    sites/all/modules/modalframe/
#    sites/all/modules/nodereference_explorer-6.x-1.1-beta6.tar.gz
#    sites/all/modules/nodereference_explorer/
#    sites/all/modules/noderelationships-6.x-1.1.tar.gz
#    sites/all/modules/noderelationships/
#    sites/all/modules/site_map-6.x-1.1.tar.gz
nothing added to commit but untracked files present (use "git add" to track)
ben@carbon:redacted/$ git pull --rebase
First, rewinding head to replay your work on top of it...
Fast-forwarded master to 527afccc7565929baf7890b42b1a34174014fee7.

Thanks for your time (and git) Ben

Jeff King· Sep 14, 2009, 11:22 UTC · re: Ben Bradshaw · lore

Re: could not detach HEAD error didn't identify the cause of the issue

On Mon, Sep 14, 2009 at 12:14:24PM +1200, Ben Bradshaw wrote:
Show 11 quoted lines
> I was asked to post this issue to the list, I've just had git tell me it
> can't detach HEAD which left me scratching mine as to the cause and fix.
> Turns out if I have local untracked files that the remote branch also
> has then this error will trigger. I have included my shell backlog
> (client data removed). In this example the site_map folder was present
> on master and I had a local, untracked copy.
> 
> git can obviosly detect this issue and stop my local copy getting in a
> bad state, but an error message such as "sites/all/modules/site_map/ is
> present in HEAD but is untracked locally, unable to apply changes" (or
> something to point the finger) would be much appreciated.
I couldn't reproduce it here; I get such a message.
  # set up forked repo, "another" exists only on master
  $ mkdir repo && cd repo
  $ git init
  $ echo content >file && git add file && git commit -m base
  $ echo content >another && git add another && git commit -m another
  $ git checkout -b other HEAD^
  $ echo changes >file && git commit -a -m changes
  # add untracked "another" here
  $ echo untracked >another
  # try rebase
  $ git rebase master
  First, rewinding head to replay your work on top of it...
  error: Untracked working tree file 'another' would be overwritten by merge.
  could not detach HEAD
  # try git pull --rebase, in case it hides the message
  $ git config branch.other.remote .
  $ git config branch.other.merge refs/heads/master
  $ git pull --rebase
  From .
   * branch            master     -> FETCH_HEAD
  First, rewinding head to replay your work on top of it...
  error: Untracked working tree file 'another' would be overwritten by merge.
  could not detach HEAD
I'll admit the "could not detach HEAD" message would probably be better as:
  rebase: unable to move HEAD to 'master', aborting rebase
or something similar.

What version of git are you using? What does my test case above produce for you?

-Peff
Ben Bradshaw· Sep 14, 2009, 21:01 UTC · lore

Re: could not detach HEAD error didn't identify the cause of the issue

Hi Jeff,

I'm using git version 1.5.6.5 - I think I can elaborate on the issue some more though. I'll step through the process that got me to the point of failure. For the purposes of this example 'ben@carbon' is me at my local machine, 'ben@staging' is our staging server. Our development setup for this project has us all working on the staging server except when we need to test something that we don't want on staging (could break things) so I also have a local copy of staging. (This seems backwards to me but it's working rather well for the short time line we have).

In this case I did the following:
1. Add module site_map to carbon
2. Install and test on carbon
3. Add module site_map to staging
4. Install and test on staging
5. git commit && git push on staging
6. git pull --rebase on carbon

I think you will need two checkouts of your repo in order to trigger this case?

Ben
Show 59 quoted lines
>
> Jeff King wrote:
>> On Mon, Sep 14, 2009 at 12:14:24PM +1200, Ben Bradshaw wrote:
>>
>>   
>>> I was asked to post this issue to the list, I've just had git tell me it
>>> can't detach HEAD which left me scratching mine as to the cause and fix.
>>> Turns out if I have local untracked files that the remote branch also
>>> has then this error will trigger. I have included my shell backlog
>>> (client data removed). In this example the site_map folder was present
>>> on master and I had a local, untracked copy.
>>>
>>> git can obviosly detect this issue and stop my local copy getting in a
>>> bad state, but an error message such as "sites/all/modules/site_map/ is
>>> present in HEAD but is untracked locally, unable to apply changes" (or
>>> something to point the finger) would be much appreciated.
>>>     
>>
>> I couldn't reproduce it here; I get such a message.
>>
>>   # set up forked repo, "another" exists only on master
>>   $ mkdir repo && cd repo
>>   $ git init
>>   $ echo content >file && git add file && git commit -m base
>>   $ echo content >another && git add another && git commit -m another
>>   $ git checkout -b other HEAD^
>>   $ echo changes >file && git commit -a -m changes
>>
>>   # add untracked "another" here
>>   $ echo untracked >another
>>
>>   # try rebase
>>   $ git rebase master
>>   First, rewinding head to replay your work on top of it...
>>   error: Untracked working tree file 'another' would be overwritten by merge.
>>   could not detach HEAD
>>
>>   # try git pull --rebase, in case it hides the message
>>   $ git config branch.other.remote .
>>   $ git config branch.other.merge refs/heads/master
>>   $ git pull --rebase
>>   From .
>>    * branch            master     -> FETCH_HEAD
>>   First, rewinding head to replay your work on top of it...
>>   error: Untracked working tree file 'another' would be overwritten by merge.
>>   could not detach HEAD
>>
>> I'll admit the "could not detach HEAD" message would probably be better as:
>>
>>   rebase: unable to move HEAD to 'master', aborting rebase
>>
>> or something similar.
>>
>> What version of git are you using? What does my test case above produce
>> for you?
>>
>> -Peff
>>
>>   
Jeff King· Sep 14, 2009, 22:39 UTC · re: Ben Bradshaw · lore

Re: could not detach HEAD error didn't identify the cause of the issue

[Please don't top-post; the usual etiquette on this list is to reply in-line].

On Tue, Sep 15, 2009 at 09:01:28AM +1200, Ben Bradshaw wrote:
> I'm using git version 1.5.6.5 - I think I can elaborate on the issue
> some more though. I'll step through the process that got me to the point
> of failure.

Thanks for following up. I was able to reproduce your problem. The more complex setup you described is not necessary to reproduce (though thank you for providing it, as it eliminated one possible source of variation). It really is just about having an untracked file 'foo' in your working tree, and the thing you are trying to rebase on top of also has 'foo' as a tracked file.

The good news is that it has already been fixed. I bisected it down to:
  commit 324c2c3177ca5b62b12029ce8821542fc29a2733
  Author: Junio C Hamano <gitster@pobox.com>
  Date:   Mon Jul 14 14:05:35 2008 -0700
      git-rebase: report checkout failure
      When detaching the HEAD to the base commit, the "git checkout"
      command could fail if, for example, upstream contains a file that
      would overrwrite a local, untracked file.  Unconditionally
      discarding the standard error stream was done to squelch the
      progress and notices back when checkout did not have -q option,
      but there is no reason to keep doing it anymore.
      Noticed by Robert Shearman.
which sounds about right. :)

It made it into git v1.6.0, but not into any of the v1.5.x maintenance series. I would suggest upgrading if you can.

-Peff

← back to recent threads