Git development
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Brian Scott Dobrovodsky <brian@pontech.com>
Cc: git@vger.kernel.org
Subject: Re: Data Integrity & un-Commited Branches
Date: Fri, 14 Sep 2007 22:51:29 -0400	[thread overview]
Message-ID: <20070915025129.GY3099@spearce.org> (raw)
In-Reply-To: <2a8a071a0709141740l144b60aevdfec2b6cdab8bb60@mail.gmail.com>

Brian Scott Dobrovodsky <brian@pontech.com> wrote:
> It was a misunderstanding of Git's work flow. By switching from 'an
> un-committed demo' to a previously committed master: I was expecting
> Git to give me the content last commited to master while at the same
> time preserving(without having to commit) the changes made in demo.
> Intuitively, this is how I expected Git to function.

You aren't the only one.

Several of my day-job coworkers have also thought the same thing.
Only they use git-gui, and have never read any of the Git docs.
Because nobody ever reads the docs.  Nope, not if you can just dial
my extension and browbeat me into giving you an answer to your most
urgent question.  :-\

My point is just that some people actually assume that work done
while having one branch checked out is related to that branch and
that branch alone and that switching a branch should put that work
on hold.  Unfortunately for me some of these people at day-job have
also just assumed Git can read their mind and forget to switch
branches at the proper times, resulting in unrelated work mashed
together for days straight (and criss-crossed merge to hell and back)
before they call me and say "MAKEITWORKNOW".
</rant>

It isn't unreasonable to want Git to save uncommitted work for the
current branch and then you switch to another, ending up with a
clean working directory when you finally get there.  Today we have
git-stash to help you with this, but I'm thinking maybe we want to
connect git-checkout with it?

I see `-s` isn't used as an option yet.  What about:

	$ git init
	$ echo master >file
	$ git add file && git commit -m initial

	$ git checkout -b demo         ;  # switch to demo
    $ echo demo >file              ;  # dirty the tree

	$ git checkout -s master       ;  # stash and switch to master
	Uncommitted changes stashed on branch 'demo'.
	$ cat file
	master

	$ git checkout demo            ;  # return to demo
	Uncommitted changes were stashed for 'demo'.
	To recover them now run:

	  git stash apply -s

    $ cat file
	master
	$ git stash apply -s
	$ cat file
	demo

The new `git stash apply -s` here is defined to find the most
recent stash for the current branch (which may not be the top of
the stash!) and apply it.

If you know you want to just reapply the stash when you switch back
we could define `git checkout -a` (also unused) to automatically
execute `git stash apply -s` if a stash is available for the
destination branch.

Just thinking out loud.  I probably won't code up a patch that
implements this but I don't think it would be too difficult for
someone else who wants to get their feet wet.

-- 
Shawn.

  reply	other threads:[~2007-09-15  2:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2a8a071a0709140028o472bcr8c82bd88e37cc4e9@mail.gmail.com>
     [not found] ` <2a8a071a0709140036l5db62c0fl5af01f75f35610ba@mail.gmail.com>
     [not found]   ` <7vk5qtd3le.fsf@gitster.siamese.dyndns.org>
2007-09-15  0:40     ` Data Integrity & un-Commited Branches Brian Scott Dobrovodsky
2007-09-15  2:51       ` Shawn O. Pearce [this message]
2007-09-15  6:24         ` Brian Scott Dobrovodsky
2007-09-15  6:32           ` Shawn O. Pearce
2007-09-15  6:37           ` Junio C Hamano
2007-09-15  7:14             ` Brian Scott Dobrovodsky
2007-09-15  7:38         ` Jan Hudec
2007-09-15  7:51           ` Shawn O. Pearce
2007-09-15 13:11             ` Nikodemus Siivola
2007-09-15 13:59               ` David Kastrup
2007-09-15 17:14                 ` Nikodemus Siivola
2007-09-15 17:33                   ` David Kastrup

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=20070915025129.GY3099@spearce.org \
    --to=spearce@spearce.org \
    --cc=brian@pontech.com \
    --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