git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Tay Ray Chuan <rctay89@gmail.com>
Cc: Jeff King <peff@peff.net>, Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 3/3] builtin/checkout: DWIM with -f -b
Date: Sun, 20 Jun 2010 22:15:39 -0700	[thread overview]
Message-ID: <7vpqzlrmo4.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <AANLkTik3QZBpOjwZHGwIXphXnaHLaBV4pUSb1OVAau9V@mail.gmail.com> (Tay Ray Chuan's message of "Mon\, 21 Jun 2010 09\:08\:27 +0800")

Tay Ray Chuan <rctay89@gmail.com> writes:

>> Yes; I thought the implication of "-f" to be destructive would be a
>> justification enough, but I agree with you that conflating the two may be
>> a bad idea.  When a user says "git checkout -f -b jch" after seeing the
>> command without "-f" fail due to existing "jch", it is quite clear that
>> the user wants to clobber the history of existing "jch" branch (why else
>> would he giving "-f"), but it is not a justification to clobber local
>> changes he has in the index and the work tree.
>
> How about doing
>
>   git checkout -f -f -b <branch>

That is not the problem I want you to solve.  What your patch does solves
only half of my issue as Peff pointed out (it lets me reuse the name of
the existing branch for an unrelated history, but it loses the local
changes I may have in my working tree).  IOW, I want to start <branch>
from scratch, based on an half-done work I started from my current branch
in my work tree.

That is what "git checkout -b <branch>" usually gives us, if the name
<branch> is not in use.

I think you were suggesting not to nuke local change with a single -f
only when -b is also in use, but I think that makes things even more
confusing to the users.  Sometimes a single -f discards local changes, but
some other times you would need double -f.  That will lead to insanity.

Perhaps we would want another option that is similar to -b but lets us
discard the named branch if it exists.  Let's call it tentatively -B.

 * git checkout -b <branch> [<start-point>]

   - starts a new branch <branch> at <start-point> commit;

   - attempts three-way merge to keep the local change forward while doing
     so, but aborts if it needs a real file-level merge;

   - complains and aborts if <branch> already exists.

   When -f is used, instead of attempting three-way merge to keep the local
   changes, it discards them.

   When -m is used, instead of failing when it needs a real file-level merge,
   it will attempt CVS/SVN "update" style merge (and can cause conflicts).

   When -B is used instead of -b, it does the three-way merge and the usual
   rejection upon a file-level merge unless -m is given.  If it can go ahead,
   but <branch> already exists, then the existing <branch> is discarded and
   replaced with the <start-point> commit.

Something like that would reduce the confusion factor and would help the
"recreate an existing branch from scratch" (or "reuse the name of an
existing branch") workflow a bit.

  reply	other threads:[~2010-06-21  5:15 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-20 16:33 [PATCH 0/3] DWIM with "git checkout -f -b" Tay Ray Chuan
2010-06-20 16:33 ` [PATCH 1/3] add tests for checkout -b Tay Ray Chuan
2010-06-20 16:33   ` [PATCH 2/3] t2018-checkout-branch.sh: show that checkout -f -b doesn't DWIM Tay Ray Chuan
2010-06-20 16:33     ` [PATCH 3/3] builtin/checkout: DWIM with -f -b Tay Ray Chuan
2010-06-20 19:12       ` Junio C Hamano
2010-06-20 20:11         ` Jeff King
2010-06-20 21:07           ` Clemens Buchacher
2010-06-20 21:10           ` Junio C Hamano
2010-06-20 21:16             ` Jeff King
2010-06-21  0:09               ` Junio C Hamano
2010-06-21  1:08                 ` Tay Ray Chuan
2010-06-21  5:15                   ` Junio C Hamano [this message]
2010-06-21 17:19                     ` [PATCH 0/3] teach git-checkout -B WAS " Tay Ray Chuan
2010-06-21 17:19                       ` [PATCH 1/3] add tests for checkout -b Tay Ray Chuan
2010-06-21 17:19                         ` [PATCH 2/3] builtin/checkout: change -b from an OPTION_STRING to a OPTION_SET_INT Tay Ray Chuan
2010-06-21 17:19                           ` [PATCH 3/3] builtin/checkout: learn -B Tay Ray Chuan
2010-06-23 18:36                             ` Junio C Hamano
2010-06-23 19:13                               ` Tay Ray Chuan
2010-06-21 23:04                           ` [PATCH 2/3] builtin/checkout: change -b from an OPTION_STRING to a OPTION_SET_INT Erick Mattos
2010-06-23 19:04                             ` Tay Ray Chuan
2010-06-23 21:37                               ` Erick Mattos
2010-06-21 17:24                       ` [PATCH 0/3] teach git-checkout -B WAS builtin/checkout: DWIM with -f -b Tay Ray Chuan
2010-06-21 21:30                         ` Erick Mattos
2010-06-23 19:28                       ` [PATCH v2 " Tay Ray Chuan
2010-06-23 19:28                         ` [PATCH v2 1/3] add tests for checkout -b Tay Ray Chuan
2010-06-23 19:28                           ` [PATCH v2 2/3] builtin/checkout: reword hint for -b Tay Ray Chuan
2010-06-23 19:29                             ` [PATCH v2 3/3] builtin/checkout: learn -B Tay Ray Chuan
2010-06-21  2:58               ` [PATCH 3/3] builtin/checkout: DWIM with -f -b Michel Lespinasse
2010-06-21  4:09                 ` Michel Lespinasse

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=7vpqzlrmo4.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=rctay89@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).