threads / rfc / 32430

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

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

## tl;dr

7 messages between Dec 21, 2012 and Dec 21, 2012.

replies: 6people: 3as markdown or json

Junio C Hamano· Dec 21, 2012, 15:58 UTC · lore

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· Dec 21, 2012, 16:55 UTC · lore

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

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· Dec 21, 2012, 17:12 UTC · re: Martin von Zweigbergk · lore

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

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· Dec 21, 2012, 19:43 UTC · re: Junio C Hamano · lore

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

On 12/21/2012 06:12 PM, Junio C Hamano wrote:
Show 9 quoted lines
> "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.

Show 8 quoted lines
> 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· Dec 21, 2012, 21:31 UTC · re: Michael Haggerty · lore

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

On Fri, Dec 21, 2012 at 11:43 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 7 quoted lines
> 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.

Show 9 quoted lines
>>
>>     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_.

Show 13 quoted lines
>> 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· Dec 21, 2012, 21:45 UTC · re: Martin von Zweigbergk · lore

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

> 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· Dec 21, 2012, 21:59 UTC · re: Martin von Zweigbergk · lore

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

On 12/21/2012 10:31 PM, Martin von Zweigbergk wrote:
Show 14 quoted lines
> 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/

← back to recent threads