git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Ingo Brueckl <ib@wupperonline.de>
Cc: Jakub Narebski <jnareb@gmail.com>, git@vger.kernel.org
Subject: Re: question concerning branches
Date: Wed, 19 Aug 2009 14:51:17 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.2.01.0908191441070.3158@localhost.localdomain> (raw)
In-Reply-To: <4a8c51f5@wupperonline.de>



On Wed, 19 Aug 2009, Ingo Brueckl wrote:

> Jakub Narebski <jnareb@gmail.com> writes:
> 
> > You finish old work (or stash it away), _then_ you begin new work.
> 
> Ok, this helps me a little bit to understand.
> 
> The branches aren't designed to split my work, but rather something to
> collect the different parts of my work.

Hmm. Yes. That's one way of looking at it.

At the same time, thinking about it another way may explain the git 
choices in this area. There's two issues:

 - if we _don't_ carry the edits around across branch switches, then what 
   would we do?

   Basically, since you haven't committed things, it's kind of floating 
   around. You switch to another branch, what should we do? There are 
   really only two choices: either we'd need to 'stash' the state with the 
   branch we switch away from (which is apparently what you expected), or 
   we need to just move the changes to the new branch (which is what git 
   does, or complains if it cannot).

   Now, 'stashing' the changes is actually very much against the whole git 
   philosophy. Git was built up around the index and the database, and 
   branches have always been pointers to the top-of-commit, so there 
   literally isn't any way to stash things that makes sense. Sure, later 
   on we ended up having the 'stash' command, but that's totally separate 
   from branches, and is an independently useful thing.

 - One of the big reasons to act like git does is that the way at least 
   _I_ work is to actually create a new branch with the explicit intention 
   of committing work I have already done!

   IOW, your example was

	git branch test
	git checkout test
	# edit foo.bar
	git checkout master

   and you were surprised that the edit followed you back to the "master" 
   branch, but what is actualyl a much more natural way of working is

	# edit foo.bar
	# realize that this was actually the start of a new feature
	git branch new-feature
	git checkout new-feature
	# maybe continue to edit foo.bar until it's all good
	git commit -a

   ie the git behavior explicitly _encourages_ you to not have to decide 
   before-the-fact to create a branch - it may be that only after you've 
   done the changes do you realize that "oops, these changes were _way_ 
   more intrusive than I originally anticipated, and I don't want to 
   commit them on the master branch, I want to commit them on an 
   experimental topic branch instead"

So there are two different reasons why git works the way it does: a pure 
implementation reason ("working any other way would not fit the git 
model") and a practical workflow reason ("you are _expected_ to move dirty 
state around with your branches, because one common case is to create a 
branch _for_ that dirty state").

			Linus

  parent reply	other threads:[~2009-08-19 21:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-19 17:33 question concerning branches Ingo Brueckl
2009-08-19 18:07 ` Bruce Stephens
2009-08-19 18:07 ` Avery Pennarun
2009-08-19 18:31   ` Ingo Brueckl
2009-08-19 19:08     ` Jakub Narebski
2009-08-19 19:45       ` Ingo Brueckl
2009-08-19 19:50         ` Avery Pennarun
2009-08-20  7:57           ` Matthieu Moy
2009-08-19 19:53         ` Jacob Helwig
2009-08-19 20:01         ` Jakub Narebski
2009-08-19 20:39         ` Theodore Tso
2009-08-19 20:57           ` Jakub Narebski
2009-08-20 17:37             ` Theodore Tso
2009-08-19 21:51         ` Linus Torvalds [this message]
2009-08-20  3:01           ` Randal L. Schwartz
2009-08-20 12:46           ` Ingo Brueckl
2009-08-20 13:47             ` Johannes Sixt
2009-08-20 14:59               ` Jakub Narebski
2009-08-19 18:35 ` Junio C Hamano
2009-08-19 19:21   ` Ingo Brueckl
2009-08-20  7:33     ` Andreas Ericsson

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=alpine.LFD.2.01.0908191441070.3158@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=ib@wupperonline.de \
    --cc=jnareb@gmail.com \
    /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).