git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Avery Pennarun" <apenwarr@gmail.com>
To: "Nicolas Pitre" <nico@cam.org>
Cc: "Johan Herland" <johan@herland.net>,
	git@vger.kernel.org, "Stephan Beyer" <s-beyer@gmx.net>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Pieter de Bie" <pdebie@ai.rug.nl>
Subject: Re: [RFC] Detached-HEAD reminder on commit?
Date: Thu, 4 Sep 2008 00:50:18 -0400	[thread overview]
Message-ID: <32541b130809032150i418014bdo8a838f529e109f50@mail.gmail.com> (raw)
In-Reply-To: <alpine.LFD.1.10.0809021849390.23787@xanadu.home>

On Tue, Sep 2, 2008 at 6:53 PM, Nicolas Pitre <nico@cam.org> 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

  reply	other threads:[~2008-09-04  4:51 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-02 19:31 [RFC] Detached-HEAD reminder on commit? Pieter de Bie
2008-09-02 19:43 ` Robin Rosenberg
2008-09-02 20:24 ` Nicolas Pitre
2008-09-02 20:26 ` Matthieu Moy
2008-09-02 20:35   ` Nicolas Pitre
2008-09-02 20:39 ` Junio C Hamano
2008-09-02 21:05   ` Stephan Beyer
2008-09-02 21:39     ` Johan Herland
2008-09-02 21:44       ` Jeff King
2008-09-02 21:51         ` Jeff King
2008-09-03  7:45         ` Johan Herland
2008-09-03  8:07           ` Junio C Hamano
2008-09-03  9:47             ` Johan Herland
2008-09-03 13:15           ` Jeff King
2008-09-03 13:34             ` Jeff King
2008-09-03 13:46               ` Andreas Ericsson
2008-09-03 16:49               ` Daniel Barkalow
2008-09-03 18:07                 ` Jeff King
2008-09-03 19:36                   ` Junio C Hamano
2008-09-03 19:41                     ` Jeff King
2008-09-03 14:11             ` Wincent Colaiuta
2008-09-03 18:08               ` Jeff King
2008-09-03 15:16           ` Nicolas Pitre
2008-09-02 21:58       ` Junio C Hamano
2008-09-02 22:53       ` Nicolas Pitre
2008-09-04  4:50         ` Avery Pennarun [this message]
2008-09-04  5:31           ` Junio C Hamano
2008-09-05 23:43             ` Junio C Hamano
2008-09-02 21:51     ` Pieter de Bie
2008-09-02 22:11       ` Jakub Narebski
2008-09-02 22:50         ` Junio C Hamano
2008-09-02 22:58           ` Nicolas Pitre
2008-09-03 11:27       ` Pieter de Bie
2008-09-05 17:13         ` [PATCH] Builtin-commit: show on which branch a commit was added Pieter de Bie
2008-09-07  5:27           ` Junio C Hamano
2008-09-07  5:59             ` Junio C Hamano
2008-09-07 23:05               ` [PATCH 1/2] pretty.c: add %% format specifier Pieter de Bie
2008-09-07 23:05                 ` [PATCH 2/2] builtin-commit: show on which branch a commit was added Pieter de Bie
2008-09-21 10:42             ` [PATCH] Builtin-commit: " Jeff King
2008-09-29 20:09               ` Pieter de Bie
2008-09-29 22:44                 ` Jeff King
2008-09-30  6:13                   ` Andreas Ericsson
2008-09-30  6:16                     ` Jeff King
2008-09-30  9:45                       ` Andreas Ericsson
2008-09-30  9:52                       ` [PATCH] git commit: Reformat output somewhat Andreas Ericsson
2008-09-30  6:37                     ` [PATCH] Builtin-commit: show on which branch a commit was added Wincent Colaiuta
2008-09-30  7:09                       ` Jeff King
2008-09-30  9:59                         ` Andreas Ericsson
2008-10-01  3:14                           ` Jeff King
2008-10-01  8:13                             ` Andreas Ericsson
2008-10-01 15:10                               ` Shawn O. Pearce
2008-10-01 15:22                                 ` Andreas Ericsson
2008-10-01 15:25                                 ` Jeff King
2008-10-01 15:36                                   ` Shawn O. Pearce
2008-10-01 15:42                                     ` Jeff King
2008-10-01 15:44                                       ` Shawn O. Pearce
2008-10-01 21:06                                         ` [PATCH] git commit: Repaint the output format bikeshed (again) Andreas Ericsson
2008-10-01 22:06                                           ` Jeff King
2008-10-01 22:31                                             ` Jeff King
2008-10-02  5:40                                               ` Andreas Ericsson
2008-10-02 21:13                                                 ` Jeff King
2008-10-03  0:15                                                   ` Shawn O. Pearce
2008-10-03  4:24                                                     ` Jeff King
2008-10-03 14:09                                                       ` Shawn O. Pearce
2008-10-04  2:13                                                         ` Jeff King
2008-10-02  8:36                                             ` Wincent Colaiuta
2008-10-01 15:18                               ` [PATCH] Builtin-commit: show on which branch a commit was added Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32541b130809032150i418014bdo8a838f529e109f50@mail.gmail.com \
    --to=apenwarr@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johan@herland.net \
    --cc=nico@cam.org \
    --cc=pdebie@ai.rug.nl \
    --cc=s-beyer@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).