# [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?

7 messages from 2012-12-21 to 2012-12-21. Participants: Junio C Hamano, Martin von Zweigbergk, Michael Haggerty.
Thread: https://gitlist.dev/t/32430

## Junio C Hamano, 2012-12-21 15:58

Subject: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <7v8v8r2y8s.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v8v8r2y8s.fsf%40alter.siamese.dyndns.org

```
When you want to redo a branch forked from another branch (say
'master'), a handy way to work is to first detach HEAD at the
previous fork point:

    $ git checkout master...branch

and build an updated history on top of this state.  Once you are
done, you can verify your results with commands like:

    $ git show-branch branch HEAD
    $ git diff branch HEAD

and then finish it off with:

    $ git checkout -B branch

This way, you can keep the history of the previous round on 'branch'
until you are done with the new history you build on the detached
HEAD state, and if you do not like updated history, you can reset
back to branch@{1} easily.

But you may not even need to have such an easy access to the old
history and just want to restart, with:

    $ git checkout -B branch <old fork point>

Unfortunately, master...branch syntax does not seem to work for
specifying the "old fork point" for this purpose, even though we
have special case to support the syntax in the "detach at that
commit" case (the first command line example in this message).

Perhaps we should teach the <start-point> parser this syntax as
well?

```

## Martin von Zweigbergk, 2012-12-21 16:55

Subject: Fwd: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <CANiSa6ibS7ORY=QMS3WQzXYJQQH4ZYvPO75qgLgv-oWGMSBBrw@mail.gmail.com>
URL: https://gitlist.dev/e/CANiSa6ibS7ORY%3DQMS3WQzXYJQQH4ZYvPO75qgLgv-oWGMSBBrw%40mail.gmail.com
In-Reply-To: <CANiSa6jP_JN+DpDgYpWA9Aky9REJvFq3aR3Yj0vF3+axWvtmsw@mail.gmail.com>

```
Oops, meant for all of you.


---------- Forwarded message ----------
From: Martin von Zweigbergk <martinvonz@gmail.com>
Date: Fri, Dec 21, 2012 at 8:45 AM
Subject: Re: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
To: Junio C Hamano <gitster@pobox.com>


On Fri, Dec 21, 2012 at 7:58 AM, Junio C Hamano <gitster@pobox.com> wrote:
>     $ git checkout -B branch <old fork point>
>
> Unfortunately, master...branch syntax does not seem to work for
> specifying the "old fork point" for this purpose

I have personally always found it confusing to use the same syntax for
specifying ranges/sets and single revisions. I keep forgetting what
"git diff A..B" does. I know it doesn't do what I expect (i.e. "git
diff $(git merge-base A B) B"), but I don't know what it does (maybe
same as "git diff A B" (?), but that's besides the point). Having
worked a bit on rebase, I know that $onto can also take the "A...B"
form. So there is clearly some precedence for the "..." syntax to
refer to a revision in some contexts. I would have much preferred if
it was possible to make the revision parser generally interpret e.g.
"A.^.B" as "the merge base of A and B" (failing if not exactly one).
It seems like something that must have come up before. Is there a
particular reason this would not be a good idea?

```

## Junio C Hamano, 2012-12-21 17:12

Subject: Re: Fwd: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <7vr4mj1g8j.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr4mj1g8j.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CANiSa6ibS7ORY=QMS3WQzXYJQQH4ZYvPO75qgLgv-oWGMSBBrw@mail.gmail.com>

```
Martin von Zweigbergk <martinvonz@gmail.com> writes:

> I keep forgetting what "git diff A..B" does.

"diff" is always about two endpoints, not the path that connects
these two endpoints (aka "range"), and when you want to "diff"
between two commits, you say "diff A B".  "A..B" happens to be
accepted as such only by accident (e.g. the old command line parser
did not have a reliable way to tell "^A B" and "A..B" apart), not by
design.

    side note: incidentally, now we have rev_cmdline_info support,
    we could start deprecating "diff A..B" syntax.

The special case "git checkout master...branch" is not about
specifying a range.  The command knows it wants a single point (not
two endpoints, nor a range), and A...B as a notation to specify a
single point is $(merge-base A B).

> I would have much preferred if
> it was possible to make the revision parser generally interpret e.g.
> "A.^.B" as "the merge base of A and B" (failing if not exactly one).

Actually, in many places where the command line parser knows it
wants a single point, and never a range, we should be able to apply
the "A...B as a notation to specify a single point" rule.  

Of course you could come up with a symbol other than "..." for that
purpose, and migrate the current "git checkout A...B" special case
to use that other symbol, but that would be more work and also you
would need to retrain existing users.

```

## Michael Haggerty, 2012-12-21 19:43

Subject: Re: Fwd: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <50D4BBDC.6030700@alum.mit.edu>
URL: https://gitlist.dev/e/50D4BBDC.6030700%40alum.mit.edu
In-Reply-To: <7vr4mj1g8j.fsf@alter.siamese.dyndns.org>

```
On 12/21/2012 06:12 PM, Junio C Hamano wrote:
> "diff" is always about two endpoints, not the path that connects
> these two endpoints (aka "range"), and when you want to "diff"
> between two commits, you say "diff A B".  "A..B" happens to be
> accepted as such only by accident (e.g. the old command line parser
> did not have a reliable way to tell "^A B" and "A..B" apart), not by
> design.
> 
>     side note: incidentally, now we have rev_cmdline_info support,
>     we could start deprecating "diff A..B" syntax.

I often find myself using "git diff A..B" syntax when using the command
line history because the previous command used "A..B"; e.g.,

    git log A..B
    git diff A..B

It's quick to recall the previous command, edit "log" -> "diff", and
press enter; having to remove the dots would require a few extra keypresses.

> Actually, in many places where the command line parser knows it
> wants a single point, and never a range, we should be able to apply
> the "A...B as a notation to specify a single point" rule.  
> 
> Of course you could come up with a symbol other than "..." for that
> purpose, and migrate the current "git checkout A...B" special case
> to use that other symbol, but that would be more work and also you
> would need to retrain existing users.

OTOH making A...B sometimes mean a range and sometimes a merge-base
(depending on context) adds a confusing non-uniformity, and also has the
disadvantage of making merge-base shorthand unavailable in contexts that
allow a range.

OTOOH git already has so many notations that can be used on the command
line; inventing yet another one would make it that much more overwhelming.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

```

## Martin von Zweigbergk, 2012-12-21 21:31

Subject: Re: Fwd: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <CANiSa6hcDHTpZnAXR3zxdv-H4r-yRjuSx_kgE5V1rSFk_pNhOA@mail.gmail.com>
URL: https://gitlist.dev/e/CANiSa6hcDHTpZnAXR3zxdv-H4r-yRjuSx_kgE5V1rSFk_pNhOA%40mail.gmail.com
In-Reply-To: <50D4BBDC.6030700@alum.mit.edu>

```
On Fri, Dec 21, 2012 at 11:43 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
> On 12/21/2012 06:12 PM, Junio C Hamano wrote:
>> "diff" is always about two endpoints, not the path that connects
>> these two endpoints (aka "range"), and when you want to "diff"
>> between two commits, you say "diff A B".  "A..B" happens to be
>> accepted as such only by accident (e.g. the old command line parser
>> did not have a reliable way to tell "^A B" and "A..B" apart), not by
>> design.

Off topic: I also find it hard to wrap my head around what diffing
against a negative revision would mean. Looking at the result of
running it, it seems to be the same as diffing against a positive one.

>>
>>     side note: incidentally, now we have rev_cmdline_info support,
>>     we could start deprecating "diff A..B" syntax.
>
> I often find myself using "git diff A..B" syntax when using the command
> line history because the previous command used "A..B"; e.g.,
>
>     git log A..B
>     git diff A..B

The problem with this, to me, if it wasn't clear, is that "git log
A..B" shows you is new _since B branched off from A_, while "git diff
A..B" shows you what has changed _between A and B_.

>> Actually, in many places where the command line parser knows it
>> wants a single point, and never a range, we should be able to apply
>> the "A...B as a notation to specify a single point" rule.
>>
>> Of course you could come up with a symbol other than "..." for that
>> purpose, and migrate the current "git checkout A...B" special case
>> to use that other symbol, but that would be more work and also you
>> would need to retrain existing users.
>
> OTOH making A...B sometimes mean a range and sometimes a merge-base
> (depending on context) adds a confusing non-uniformity, and also has the
> disadvantage of making merge-base shorthand unavailable in contexts that
> allow a range.

And making it unavailable in contexts where the command was not
specifically implemented to support it. I'm sure there are many
scripts out there that use "git ... $(git merge-base A B) ..." that
could be simplified if rev-parse could resolve a merge base.

> OTOOH git already has so many notations that can be used on the command
> line; inventing yet another one would make it that much more overwhelming.

Agreed.

```

## Junio C Hamano, 2012-12-21 21:45

Subject: Re: Fwd: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <CAPc5daWN_a0d2o37CkRk5n9bc4dy5_Zan22dN81waT=-+b7pVA@mail.gmail.com>
URL: https://gitlist.dev/e/CAPc5daWN_a0d2o37CkRk5n9bc4dy5_Zan22dN81waT%3D-%2Bb7pVA%40mail.gmail.com
In-Reply-To: <CANiSa6hcDHTpZnAXR3zxdv-H4r-yRjuSx_kgE5V1rSFk_pNhOA@mail.gmail.com>

```
> Off topic: I also find it hard to wrap my head around what diffing
> against a negative revision would mean. Looking at the result of
> running it, it seems to be the same as diffing against a positive one.

That is not an off-topic at all, but is the crux of "diff A..B" being
a hysterical raisins.
It is parsed as and converted to "diff ^A B" by the revision command
line parser in
setup_revisions(), and the caller *guesses* what the command line
originally said by
inspecting that there are two revs in rev.pending[] array, the first
one is negative and
the second one is positive, to infer that the user typed "diff A..B"
and then finally
decides to compare A and B.

This was done before we introduced rev.cmdline_info to record what was
given from
the command line to result in the set of commits in rev.pending array.
If we were
writing "git diff" UI from scratch today, we wouldn't be looking at
rev.pending but
would be looking at rev.cmdline_info and we can differenciate between
"A B", "^A B",
and "A..B" (and reject the latter two as nonsense).

```

## Michael Haggerty, 2012-12-21 21:59

Subject: Re: Fwd: [RFC/FR] Should "git checkout (-B|-b) branch master...branch" work?
Message-ID: <50D4DBD0.7050601@alum.mit.edu>
URL: https://gitlist.dev/e/50D4DBD0.7050601%40alum.mit.edu
In-Reply-To: <CANiSa6hcDHTpZnAXR3zxdv-H4r-yRjuSx_kgE5V1rSFk_pNhOA@mail.gmail.com>

```
On 12/21/2012 10:31 PM, Martin von Zweigbergk wrote:
> On Fri, Dec 21, 2012 at 11:43 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
>> On 12/21/2012 06:12 PM, Junio C Hamano wrote:
>>>     side note: incidentally, now we have rev_cmdline_info support,
>>>     we could start deprecating "diff A..B" syntax.
>>
>> I often find myself using "git diff A..B" syntax when using the command
>> line history because the previous command used "A..B"; e.g.,
>>
>>     git log A..B
>>     git diff A..B
> 
> The problem with this, to me, if it wasn't clear, is that "git log
> A..B" shows you is new _since B branched off from A_, while "git diff
> A..B" shows you what has changed _between A and B_.

You are quite right, of course, though in many useful cases they are the
same.  But I guess I should just buck myself up for the new orthodoxy :-)

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

```
