From: "Björn Steinbrink" <B.Steinbrink@gmx.de>
To: Dmitry Potapov <dpotapov@gmail.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Michael J Gruber <git@drmicha.warpmail.net>,
git@vger.kernel.org
Subject: Re: What are branches?
Date: Mon, 20 Apr 2009 23:04:29 +0200 [thread overview]
Message-ID: <20090420210429.GC17241@atjola.homenet> (raw)
In-Reply-To: <20090420184746.GG25059@dpotapov.dyndns.org>
On 2009.04.20 22:47:46 +0400, Dmitry Potapov wrote:
> On Mon, Apr 20, 2009 at 04:25:38PM +0200, Johannes Schindelin wrote:
> >
> > On Mon, 20 Apr 2009, Dmitry Potapov wrote:
> >
> > > When you create a new commit, it is always belong to _one_ branch and
> > > never to two or more branches.
> >
> > Certainly you forgot about detached HEADs?
>
> I suppose it is a branch without any name given to it,
Strictly, you don't give names to branches with git. But if you do, that
has some "interesting" consequences. Let's say you have "master" checked
out and do:
git branch foo
git checkout -b bar
You now have a single line of development and three names that reference
it. So your branch would have three names, right?
git commit --allow-empty -m 123
Now, your previous branch only has two names left, and you have a new
branch with a single name.
git reset foo
And now, you again have three names for the original branch and the new
branch is unnamed.
So when you go and say that branch heads provide names for branches, your
actions become pretty weird. "git branch <name>" gives new names to
existing branches, and "git commit" is what actually creates the branch
(this is always the case), plus it might remove a name from an existing
branch. "git reset" removes a name from one branch and gives it to
another branch. "git rebase" does the same, and it's in general not
valid to think of rebase as rewriting the branch's history. For example:
git checkout -b for-v2 for-v1
git rebase --onto v2 v1 for-v2
That would create a new branch, add for-v2 as a name for it and remove
the for-v2 name from the old branch (so the number of names for it is
reduced by one, but it's still called for-v1)
So, IMHO, if you think the whole "branches have names" scheme through,
using the "a branch is a line of development" definition and keeping in
mind how git actually works, using branch heads, things do get pretty
confusing.
> but it is an advanced feature. I don't think many beginners know about
> it, so it is something that can confuse beginners.
But it should not. In my experience, telling someone how HEAD works
often leads to some kind of epiphany. And a detached HEAD is probably
easier to grasp than the "normal" situation where HEAD is a symbolic
reference to some branch head. Btw, writing those emails, I can now
understand _why_ the explanation of HEAD and how it controls which
reference gets updated upon e.g. "git commit" might be so helpful to
some users. It might just be the fact that they suddenly realize that
git does not have a true directly user-accesible notion of branches, but
just branch heads. I can imagine how users that think in branches that
have a start and an end might get confused.
Björn
next prev parent reply other threads:[~2009-04-20 21:06 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-19 15:17 What are branches? Johannes Schindelin
2009-04-19 15:24 ` Michael Witten
2009-04-19 22:10 ` Tuncer Ayaz
2009-04-19 22:29 ` Johannes Schindelin
2009-04-19 22:34 ` Tuncer Ayaz
2009-04-20 11:32 ` Dmitry Potapov
2009-04-20 12:07 ` Michael J Gruber
2009-04-20 13:24 ` Dmitry Potapov
2009-04-20 13:52 ` Michael J Gruber
[not found] ` <200904201614.07735.fge@one2team.com>
2009-04-20 14:27 ` Michael J Gruber
2009-04-20 18:40 ` Dmitry Potapov
2009-04-20 20:58 ` Junio C Hamano
2009-04-20 22:08 ` Marius Vollmer
2009-04-21 0:53 ` Junio C Hamano
2009-04-21 11:41 ` Dmitry Potapov
2009-04-20 14:25 ` Johannes Schindelin
2009-04-20 16:06 ` Björn Steinbrink
2009-04-20 18:59 ` Jakub Narebski
2009-04-20 20:23 ` Björn Steinbrink
2009-04-24 13:08 ` Jakub Narebski
2009-04-24 16:29 ` Björn Steinbrink
2009-04-20 18:47 ` Dmitry Potapov
2009-04-20 19:19 ` Johannes Schindelin
2009-04-20 19:24 ` Michał Kiedrowicz
2009-04-20 20:16 ` Dmitry Potapov
2009-04-20 21:04 ` Björn Steinbrink [this message]
2009-04-20 16:13 ` Brian Gernhardt
2009-04-25 11:11 ` Felipe Contreras
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=20090420210429.GC17241@atjola.homenet \
--to=b.steinbrink@gmx.de \
--cc=Johannes.Schindelin@gmx.de \
--cc=dpotapov@gmail.com \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
/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).