Re: [RFC] Detached-HEAD reminder on commit?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 2, 2008 at 6:53 PM, Nicolas Pitre <nico@xxxxxxx> wrote:
> On Tue, 2 Sep 2008, Johan Herland wrote:
>> Vienna:git pieter$ ./git commit --allow-empty -m"test"
>> You are on a detached head, so this commit would not be recorded in a
>> branch. If you don't want to lose this commit, please switch to a (new)
>> branch before committing. If you know what you're doing, and want to
>> proceed on a detached HEAD, please enable commit.detached in your
>> configuration (git config --global commit.detached true)
>>
>> ...but I sympathize with those that think this is overkill.
>
> This is going over board indeed.
>
> Adding commits to a detached head is _cool_, and it is also _useful_ in
> many occasions.  Let's not obfuscate that capability.
>
> Adding an extra line of warning when the commit is done is fine, but
> more than that is too much IMHO.

I think maybe we're looking at this the wrong way.  The bad thing
isn't committing to a detached HEAD; the bad thing is detaching the
HEAD *by accident* in the first place.

Why do people (including me) spend so much time with a detached HEAD?
I think it happens mainly for the following reasons:

1) Checking out a remote branch "git checkout origin/master" detaches
my HEAD, which is kind of bad, since it's such a common thing to want
to do.  And "git checkout -b master origin/master" is *not* actually
what I want to do, *most* of the time. What I actually want is for git
to remember that I'm on origin/master, but not let me change
origin/master, because it's a remote branch.  If I want to make
changes, I need to first make a topic branch, with "git checkout -b
topic".  git should prevent me from committing until I do.

2) git-rebase and git-am detach the HEAD while they work.  I think
this is fine, but: you shouldn't be able to *reattach* the HEAD
without first aborting the rebase or am operations.  When I've lost my
work, it's usually because I turned out to be in the middle of a
rebase or am and forgot about it, then I checked out another branch
and did some work, then ran git-rebase --abort, and oops! It moved me
somewhere else.  git should prevent me from switching branches when a
rebase or am is in progress.

3) git-submodule detaches and moves the HEAD of submodules
automatically.  This is a whole separate discussion :)

The remaining situations where someone is working on a detached HEAD
(eg. checking out a particular commit, or actually implementing
git-rebase like operations) seem to be pretty obviously *intentional*,
and in that case, git should stay out of their way and let them do
what they're doing.

I believe the reason this is such a hotly debated topic is that people
confuse situations #1 and #2, and try to apply the same solution to
both.  But in situation #1, you want to be able to switch branches; in
situation #2, you want to be able to commit.  They are different
situations, even though technically the fact that "I'm on a detached
HEAD!" is the same.

Have fun,

Avery
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux