# Using "-" for "previous branch" failing with rebase

4 messages from 2014-03-15 to 2014-03-18. Participants: Tim Chase, Junio C Hamano.
Thread: https://gitlist.dev/t/36178

## Tim Chase, 2014-03-15 20:29

Subject: Using "-" for "previous branch" failing with rebase
Message-ID: <20140315152924.26c3294e@bigbox.christie.dr>
URL: https://gitlist.dev/e/20140315152924.26c3294e%40bigbox.christie.dr

```
I recently learned that there are several places where git allows use
of "-" to refer to the previous branch, e.g.

  git checkout -b dev
  # hack, hack
  git checkout master
  git merge -
  git checkout -

However, it doesn't seem to understand "-" in the context of a rebase:

  git checkout branch_a
  # hack
  git commit -a
  git checkout branch_b
  # hack
  git commit -a
  git rebase -         # I'd expect to rebase onto branch_a

but I get

  fatal: Needed a single revision
  invalid upstream -

Issuing

  git rebase branch_a

does exactly what I'd expect (as "git checkout -" puts me on
"branch_a").

Is this just an interface inconsistency or is there a some technical
reason this doesn't work (or, has it been addressed/fixed, and just
not pulled into Debian Stable's 1.7.10.4 version of git)?

Thanks,

-tkc

```

## Junio C Hamano, 2014-03-17 06:37

Subject: Re: Using "-" for "previous branch" failing with rebase
Message-ID: <7vppll2uvp.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vppll2uvp.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20140315152924.26c3294e@bigbox.christie.dr>

```
Tim Chase <git@tim.thechases.com> writes:

> Is this just an interface inconsistency or is there a some technical
> reason this doesn't work (or, has it been addressed/fixed, and just
> not pulled into Debian Stable's 1.7.10.4 version of git)?

It is merely that nobody thought "rebase" would benefit from such a
short-hand, I think.

    Teach more commands that operate on branch names about "-"
    shorthand for "the branch we were previously on", like we did
    for "git merge -" sometime after we introduced "git checkout -"

has been sitting in my "leftover bits" list at

    http://git-blame.blogspot.com/p/leftover-bits.html

for quite some time.  Hint, hint...

```

## Tim Chase, 2014-03-18 01:47

Subject: Re: Using "-" for "previous branch" failing with rebase
Message-ID: <20140317204744.6ac795a0@bigbox.christie.dr>
URL: https://gitlist.dev/e/20140317204744.6ac795a0%40bigbox.christie.dr
In-Reply-To: <7vppll2uvp.fsf@alter.siamese.dyndns.org>

```
On 2014-03-16 23:37, Junio C Hamano wrote:
> Tim Chase <git@tim.thechases.com> writes:
> 
> > Is this just an interface inconsistency or is there a some
> > technical reason this doesn't work (or, has it been
> > addressed/fixed, and just not pulled into Debian Stable's
> > 1.7.10.4 version of git)?
> 
> It is merely that nobody thought "rebase" would benefit from such a
> short-hand, I think.
> 
>     Teach more commands that operate on branch names about "-"
>     shorthand for "the branch we were previously on", like we did
>     for "git merge -" sometime after we introduced "git checkout -"
> 
> has been sitting in my "leftover bits" list at
> 
>     http://git-blame.blogspot.com/p/leftover-bits.html
> 
> for quite some time.  Hint, hint...

Not sure if the "Hint, hint" was intended for me, as I'm not exactly
a git hacker.  I did find another place where I reached for it
instinctively (now that I use it regularly with checkout/merge):
git-diff.

  git checkout some_branch
  #hack
  git commit -m "..."
  git checkout other_branch
  # hmm...what's different between these branches?
  git diff -

which I would have expected to act something like

  git diff some_branch..other_branch

Just for the archives.

-tkc




(or possibly the reverse)

```

## Junio C Hamano, 2014-03-18 18:59

Subject: Re: Using "-" for "previous branch" failing with rebase
Message-ID: <xmqqr45z8h9d.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqr45z8h9d.fsf%40gitster.dls.corp.google.com
In-Reply-To: <20140317204744.6ac795a0@bigbox.christie.dr>

```
Tim Chase <git@tim.thechases.com> writes:

> On 2014-03-16 23:37, Junio C Hamano wrote:
>> Tim Chase <git@tim.thechases.com> writes:
>> 
>> > Is this just an interface inconsistency or is there a some
>> > technical reason this doesn't work (or, has it been
>> > addressed/fixed, and just not pulled into Debian Stable's
>> > 1.7.10.4 version of git)?
>> 
>> It is merely that nobody thought "rebase" would benefit from such a
>> short-hand, I think.
>> 
>>     Teach more commands that operate on branch names about "-"
>>     shorthand for "the branch we were previously on", like we did
>>     for "git merge -" sometime after we introduced "git checkout -"
>> 
>> has been sitting in my "leftover bits" list at
>> 
>>     http://git-blame.blogspot.com/p/leftover-bits.html
>> 
>> for quite some time.  Hint, hint...
>
> Not sure if the "Hint, hint" was intended for me,...

No.  It is primarily a search-engine bait ;-) and is secondarily a
hint to any aspiring Git hackers on the list.

In general, I am not very enthused to see the single letter "-" used
where you name any commit object (like "diff").  It is a short-hand
for the @{-1} notation that names the branch name, and it is OK in
general to add support for it to the places where we expect a branch
name and not just any commit object name (e.g. "checkout -"), but
maybe it is just me who was heavily involved in the original design.

```
