All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: git@vger.kernel.org
Subject: Re: Better cooperation between checkouts and stashing
Date: Mon, 01 Feb 2010 12:40:49 -0800	[thread overview]
Message-ID: <7vhbq0wuy6.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 4B67227A.7030908@web.de

Markus Elfring <Markus.Elfring@web.de> writes:

> The content control tool "Git" maintains a single file system view that can be
> actively worked on. It can be switched to different topic branches by the
> command "git checkout". If the current active working copy contains "dirty"
> changes, they need to be stashed away before each switch to a different issue.
> http://ariejan.net/2008/04/23/git-using-the-stash/
>
> I imagine that there are opportunities for further improvements.
> - How do you think about the feature that a checkout performs also a stash
> operation before by default and a stash would offer the option to checkout a
> branch afterwards in one step?

If you are starting from "if your work tree is dirty, you MUST stash
before checking out another branch", the suggestion is understandable.
But the thing is, that starting point is not quite correct.  And the end
result is that such a change you are suggesting would inconvenience people
greatly, I am afraid, if not designed carefully (I'll outline at the end).

Checking out another branch (branch switching) is designed to carry your
local modification across with you.  This is to allow you to start working
on something, realize that your changes are better suited for another
branch, and at that point after the fact "git checkout" that other branch,
while keeping what you have done so far.

If the original branch you started your work from and the branch you are
checking out have different contents in files you have changed (aka "your
changes conflict at the paths level"), without -m option, "git checkout"
refuses to check out the other branch, because it will need a three-way
merge to carry your changes forward, and you might not be prepared to
resolve conflicts resulting from such a merge.

In practice, however, your changes often don't conflict with the changes
between the branches at the paths level, and "git checkout" lets you carry
your local changes across just fine.  I'd say this is the majority of the
case especially for experienced git users, as they tend to commit in
smaller and more logical units than those from other SCM background.

Forcing auto-stash on them would mean they now have to pop the stash,
after checking out the other branch, which is not an improvement for them
(and remember, soon you will be part of "them" after getting used to git).
Doing an auto-pop in addition to your auto-stash "to help them" is even
worse, as you essentially made "git checkout other-branch" to always use
"-m" option.

I actually have explained this at least a few times here in the past:

 http://thread.gmane.org/gmane.comp.version-control.git/77700/focus=77708
 http://thread.gmane.org/gmane.comp.version-control.git/135661/focus=135663

but I don't see anything that states clearly that "checkout" is designed
to carry your local changes across in any documentation (I gave a cursory
look to the user manual, tutorial and checkout manual page).  Probably
"git checkout --help" needs a "Switching branches" section, just like the
planned enhancement for "Detached HEAD" section.

We _can_ start experimenting with an option (similar to "checkout -m"),
which does:

 - Internally try 'git checkout other-branch' without disturbing the user
   with any error message; if it does not fail due to paths level
   conflicts, we have successfully checked out the other branch and we are
   done;

 - If the above trial would fail for some other reason (perhaps your index
   was unmerged), then don't do anything---just fail as before;

 - Internally run 'git stash', then run 'git checkout other-branch'.  If
   either of these steps fail, you are in deep trouble.  Design what you
   have to do carefully in this case (I won't do that in this message);

 - Then finally run 'git stash pop'.

  reply	other threads:[~2010-02-01 20:41 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 18:50 Better cooperation between checkouts and stashing Markus Elfring
2010-02-01 20:40 ` Junio C Hamano [this message]
2010-02-01 21:57   ` Markus Elfring
2010-02-01 22:44     ` Eugene Sajine
2010-02-02  1:36       ` Petr Baudis
2010-02-02 10:26         ` Markus Elfring
2010-02-02 11:04           ` Petr Baudis
2010-02-09 19:20   ` Markus Elfring
2010-02-09 20:06     ` Junio C Hamano
2010-02-09 21:01       ` Markus Elfring
2010-02-18 17:43       ` Markus Elfring
2010-02-18 20:09         ` Junio C Hamano
2010-02-27 21:33   ` Markus Elfring
2010-02-27 21:51     ` Junio C Hamano
2010-02-28 13:55       ` Markus Elfring
2010-02-28 22:57         ` Michael Witten
2010-03-01 10:50       ` Markus Elfring
2010-03-01 17:02         ` Michael Witten
2010-03-01 17:23           ` Junio C Hamano
2010-03-01 18:14             ` Michael Witten
2010-03-01 18:29               ` Markus Elfring
2010-03-01 19:44               ` Junio C Hamano
2010-03-01 21:20                 ` Markus Elfring
2010-03-02  1:41                   ` Michael Witten
2010-03-02  9:35                     ` Markus Elfring
2010-03-02 17:50                       ` Junio C Hamano
2010-03-03 15:55                         ` Markus Elfring
2010-03-04  7:46                           ` Michael Witten
2010-03-04 19:55                             ` Markus Elfring
2010-03-02  9:45               ` Markus Elfring
2010-03-02 18:05                 ` Junio C Hamano
2010-03-03 16:00                   ` Markus Elfring
2010-03-17 16:35           ` [PATCH] Clarification for the command "git checkout <branch>" Markus Elfring
2010-03-17 16:44             ` Avery Pennarun
2010-03-17 17:00               ` Markus Elfring
2010-03-17 17:58               ` Junio C Hamano
2010-03-17 18:21                 ` Markus Elfring
2010-03-17 18:37                   ` Junio C Hamano
2010-03-17 18:50                     ` Michael Witten
2010-03-17 19:23                       ` Junio C Hamano
2010-03-18 10:11                 ` Markus Elfring
2010-03-18 16:36                   ` Avery Pennarun
2010-03-18 17:19                     ` Michael Witten
2010-03-18 17:33                       ` Avery Pennarun
2010-03-19  8:28                         ` Markus Elfring
2010-03-19 17:17                           ` Avery Pennarun
2010-03-20  6:00                             ` Markus Elfring
2010-03-19  8:15                       ` Markus Elfring
2010-03-30 15:57                         ` Markus Elfring
2010-03-30 22:13                           ` Junio C Hamano
2010-03-31  3:58                             ` Ramkumar Ramachandra
2010-04-01  4:52                               ` Junio C Hamano
2010-04-01 13:09                                 ` Ramkumar Ramachandra
2010-04-01  6:38                             ` Markus Elfring
2010-04-10 13:30                             ` Markus Elfring
2010-04-10 22:31                               ` Junio C Hamano

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=7vhbq0wuy6.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Markus.Elfring@web.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.