git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC] Delete current branch
@ 2013-07-19 10:35 Ramkumar Ramachandra
  2013-07-19 14:28 ` Andreas Schwab
  2013-07-19 15:08 ` Junio C Hamano
  0 siblings, 2 replies; 10+ messages in thread
From: Ramkumar Ramachandra @ 2013-07-19 10:35 UTC (permalink / raw)
  To: Git List

Hi,

Many of my ideas turn out to be really stupid, and I need to throw
away my feature branch.  So, I find myself doing this often:

  # on branch menuconfig-jk
  $ git checkout master
  $ git branch -D<BACKSAPCE>
  # er, what was the branch name again?
  $ git checkout -
  # Ah
  $ git checkout master
  $ git branch -D menuconfig-jk

So, I scripted it for myself.  Perhaps we should get the functionality
in core as `git branch -Dc` (c for "current"; or something)?

Also, perhaps a `git describe -` corresponding to `git checkout -`?
Then I can use it with --contains --all to get the name of the
previous branch.

Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 10:35 [RFC] Delete current branch Ramkumar Ramachandra
@ 2013-07-19 14:28 ` Andreas Schwab
  2013-07-19 14:35   ` Ramkumar Ramachandra
  2013-07-19 15:08 ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2013-07-19 14:28 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List

Ramkumar Ramachandra <artagnon@gmail.com> writes:

>   # er, what was the branch name again?
>   $ git checkout -

You could take a look in the reflog.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 14:28 ` Andreas Schwab
@ 2013-07-19 14:35   ` Ramkumar Ramachandra
  0 siblings, 0 replies; 10+ messages in thread
From: Ramkumar Ramachandra @ 2013-07-19 14:35 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Git List

Andreas Schwab wrote:
> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
>>   # er, what was the branch name again?
>>   $ git checkout -
>
> You could take a look in the reflog.

Yeah, or use the @{-N} revision to do that for me.  My scripted
version is essentially:

  test "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" || exit 1
  git checkout master
  git branch -D @{-1}

The main problem is the hard-coding of "master": I suppose I could
replace that with @{-1} too.

Not a big deal: I was just wondering if others use it often enough for
it to become `branch -Dc` in core; @{-N} is quite obscure.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 10:35 [RFC] Delete current branch Ramkumar Ramachandra
  2013-07-19 14:28 ` Andreas Schwab
@ 2013-07-19 15:08 ` Junio C Hamano
  2013-07-19 15:42   ` Ramkumar Ramachandra
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2013-07-19 15:08 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List

Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Many of my ideas turn out to be really stupid, and I need to throw
> away my feature branch.  So, I find myself doing this often:
>
>   # on branch menuconfig-jk
>   $ git checkout master
>   $ git branch -D<BACKSAPCE>
>   # er, what was the branch name again?
>   $ git checkout -
>   # Ah
>   $ git checkout master
>   $ git branch -D menuconfig-jk
>
> So, I scripted it for myself.  Perhaps we should get the functionality
> in core as `git branch -Dc` (c for "current"; or something)?

What branch will I be on after doing that?  Detached at that branch?

> Also, perhaps a `git describe -` corresponding to `git checkout -`

Did you know that the general way to spell the branch previously you
were on is "@{-1}" and "checkout -" is an ugly special case that is
possible only because "checkout" does not happen to take a "-" as a
valid argument that means something else (like the more usual "read
from standard input")?

Perhaps 

	$ git branch -D @{-1}

would have worked without <BACKSPACE> and everything that follows.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 15:08 ` Junio C Hamano
@ 2013-07-19 15:42   ` Ramkumar Ramachandra
  2013-07-19 16:48     ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Ramkumar Ramachandra @ 2013-07-19 15:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

Junio C Hamano wrote:
> Did you know that the general way to spell the branch previously you
> were on is "@{-1}" and "checkout -" is an ugly special case that is
> possible only because "checkout" does not happen to take a "-" as a
> valid argument that means something else (like the more usual "read
> from standard input")?

I disagree that it is ugly: it's a very commonly used shortcut that I
like.  I love it so much that I have the following in my ~/.zshrc:

function - () {
	if test "true" = "$(g rp --is-inside-work-tree 2>/dev/null)"; then
		g co -
	else
		cd - >/dev/null
	fi
}

So, I just

  $ -

to switch back and forth :)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 15:42   ` Ramkumar Ramachandra
@ 2013-07-19 16:48     ` Junio C Hamano
  2013-07-19 16:50       ` Ramkumar Ramachandra
                         ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Junio C Hamano @ 2013-07-19 16:48 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List

Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Junio C Hamano wrote:
>> Did you know that the general way to spell the branch previously you
>> were on is "@{-1}" and "checkout -" is an ugly special case that is
>> possible only because "checkout" does not happen to take a "-" as a
>> valid argument that means something else (like the more usual "read
>> from standard input")?
>
> I disagree that it is ugly: it's a very commonly used shortcut that I
> like.

It does not matter if you like it or not ;-).

I do agree that "checkout -" is 100% more pleasing to the eye than
"checkout @{-1}" from visual "prettyness" point of view.

But there is a very commonly accepted long tradition for "-" to mean
"read from the standard input", so we cannot reuse it to mean "the
branch I was previously on" for every command without first making
sure the command will never want to use "-" for the other common
purpose.

That limits the context we could use "-" and we cannot consistently
use it everywhere. I find _that_ ugly from the "design cleanliness"
point of view.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 16:48     ` Junio C Hamano
@ 2013-07-19 16:50       ` Ramkumar Ramachandra
  2013-07-19 17:08       ` Taylor Hedberg
  2013-07-19 22:52       ` Junio C Hamano
  2 siblings, 0 replies; 10+ messages in thread
From: Ramkumar Ramachandra @ 2013-07-19 16:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

Junio C Hamano wrote:
> That limits the context we could use "-" and we cannot consistently
> use it everywhere. I find _that_ ugly from the "design cleanliness"
> point of view.

Right, noted.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 16:48     ` Junio C Hamano
  2013-07-19 16:50       ` Ramkumar Ramachandra
@ 2013-07-19 17:08       ` Taylor Hedberg
  2013-07-19 19:15         ` Junio C Hamano
  2013-07-19 22:52       ` Junio C Hamano
  2 siblings, 1 reply; 10+ messages in thread
From: Taylor Hedberg @ 2013-07-19 17:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ramkumar Ramachandra, Git List

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

Junio C Hamano, Fri 2013-07-19 @ 09:48:06-0700:
> But there is a very commonly accepted long tradition for "-" to mean
> "read from the standard input", so we cannot reuse it to mean "the
> branch I was previously on" for every command without first making
> sure the command will never want to use "-" for the other common
> purpose.

It may be worth noting that Bash (and probably other shells as well)
allow you to type `cd -` to switch back to the previous working
directory. I always (apparently mistakenly) assumed that
`git checkout -` was deliberately designed to mirror that shortcut. I
think the symmetry gives it some credibility, in any case. This
alternative meaning for - is not totally without precedent.

What would it mean to check out the standard input, anyway? I cannot see
how that could ever make sense, unless `git checkout` gains some
additional capaabilities that are unrelated to its current purpose.
Maybe I am just being myopic, though.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 17:08       ` Taylor Hedberg
@ 2013-07-19 19:15         ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2013-07-19 19:15 UTC (permalink / raw)
  To: Taylor Hedberg; +Cc: Ramkumar Ramachandra, Git List

Taylor Hedberg <tmhedberg@gmail.com> writes:

> Junio C Hamano, Fri 2013-07-19 @ 09:48:06-0700:
>> But there is a very commonly accepted long tradition for "-" to mean
>> "read from the standard input", so we cannot reuse it to mean "the
>> branch I was previously on" for every command without first making
>> sure the command will never want to use "-" for the other common
>> purpose.
> ...
> What would it mean to check out the standard input, anyway?

That is my point exactly, isn't it?

You have to ask that question "What would it mean to do X on the
standard input?" for every operation X you might want to use the
short-cut "-" for.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFC] Delete current branch
  2013-07-19 16:48     ` Junio C Hamano
  2013-07-19 16:50       ` Ramkumar Ramachandra
  2013-07-19 17:08       ` Taylor Hedberg
@ 2013-07-19 22:52       ` Junio C Hamano
  2 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2013-07-19 22:52 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List

Junio C Hamano <gitster@pobox.com> writes:

> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
>> Junio C Hamano wrote:
>>> Did you know that the general way to spell the branch previously you
>>> were on is "@{-1}" and "checkout -" is an ugly special case that is
>>> possible only because "checkout" does not happen to take a "-" as a
>>> valid argument that means something else (like the more usual "read
>>> from standard input")?
>>
>> I disagree that it is ugly: it's a very commonly used shortcut that I
>> like.
>
> It does not matter if you like it or not ;-).
>
> I do agree that "checkout -" is 100% more pleasing to the eye than
> "checkout @{-1}" from visual "prettyness" point of view.
>
> But there is a very commonly accepted long tradition for "-" to mean
> "read from the standard input", so we cannot reuse it to mean "the
> branch I was previously on" for every command without first making
> sure the command will never want to use "-" for the other common
> purpose.
>
> That limits the context we could use "-" and we cannot consistently
> use it everywhere. I find _that_ ugly from the "design cleanliness"
> point of view.

Having said all that.

d18ba221 (sha1_name: support @{-N} syntax in get_sha1(), 2009-01-17)
was primarily for the follow-up patch 696acf45 (checkout: implement
"-" abbreviation, add docs and tests, 2009-01-17).  Two years after
them, we finally did 4e8115ff (merge: allow "-" as a short-hand for
"previous branch", 2011-04-07).

There is no reason we cannot continue.

As long as the addition is carefully prepared so that we know it
will not conflict (or be confused by users) with possible other uses
of "-", I do not think we would mind "git branch -D -" and other
commands to learn "-" as a synonym for @{-1}.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-07-19 22:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-19 10:35 [RFC] Delete current branch Ramkumar Ramachandra
2013-07-19 14:28 ` Andreas Schwab
2013-07-19 14:35   ` Ramkumar Ramachandra
2013-07-19 15:08 ` Junio C Hamano
2013-07-19 15:42   ` Ramkumar Ramachandra
2013-07-19 16:48     ` Junio C Hamano
2013-07-19 16:50       ` Ramkumar Ramachandra
2013-07-19 17:08       ` Taylor Hedberg
2013-07-19 19:15         ` Junio C Hamano
2013-07-19 22:52       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).