threads / discuss / 8135

~ and ^

Subject: ~ and ^

## tl;dr

6 messages between May 13, 2007 and May 13, 2007.

replies: 5people: 4as markdown or json

Sean· May 13, 2007, 18:44 UTC · lore

Would it be possible/reasonable to treat a bare ~3 (or ^) on the git command line as equivalent to "<current branch>~3" ? At least @{3} already works this way and it would be nice to do the same for the even more common tilde and hat operations. If so, it would be a small convenience to just type: "git show ~3"

Thanks, Sean

Junio C Hamano· May 13, 2007, 19:07 UTC · re: Sean · lore

Re: ~ and ^

Sean <seanlkml@sympatico.ca> writes:
Show 5 quoted lines
> Would it be possible/reasonable to treat a bare ~3 (or ^) on the git command
> line as equivalent to "<current branch>~3" ?    At least @{3} already works
> this way and it would be nice to do the same for the even more common tilde
> and hat operations.  If so, it would be a small convenience to just type:
> "git show ~3"
Interesting.

At least, "ls ~0" does not seem to get confused by bash to be the home directory of the root user, so I do not offhand think of a reason not to have ~$n as a synonym to HEAD~$n. Would that be useful? I dunno.

P.S.
Welcome back to the list ;-)
Karl Hasselström· May 13, 2007, 19:13 UTC · re: Junio C Hamano · lore

Re: ~ and ^

On 2007-05-13 12:07:21 -0700, Junio C Hamano wrote:
Show 9 quoted lines
> Sean <seanlkml@sympatico.ca> writes:
>
> > Would it be possible/reasonable to treat a bare ~3 (or ^) on the
> > git command line as equivalent to "<current branch>~3" ? At least
> > @{3} already works this way and it would be nice to do the same
> > for the even more common tilde and hat operations. If so, it would
> > be a small convenience to just type: "git show ~3"
>
> Interesting.
Yes. I think we should have this, even if just for consistency.
> At least, "ls ~0" does not seem to get confused by bash to be the
> home directory of the root user, so I do not offhand think of a
> reason not to have ~$n as a synonym to HEAD~$n.

It seems that ~foo is only expanded to foo's home if there is such a user. Since all-numeric users probably aren't common, we can probably get away with it.

> Would that be useful? I dunno.
It would allow you to say
  git log ~5..
instead of
  git log HEAD~5..
so I'd say it is useful.
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Sean· May 13, 2007, 19:49 UTC · re: Karl Hasselström · lore

Re: ~ and ^

On Sun, 13 May 2007 21:13:50 +0200 Karl Hasselström <kha@treskal.com> wrote:

> It seems that ~foo is only expanded to foo's home if there is such a
> user. Since all-numeric users probably aren't common, we can probably
> get away with it.

Someone just mentioned to me that ~# is expanded by Bash if you use the pushd command to keep a directory stack. So ~1 will stop working if you use "pushd". Maybe it'd be more confusing than helpful. On the other hand, there's probably no reason for Git to just give an error message if it receives a properly escaped lone "~", "~#", or "^".

Sean
Sean· May 13, 2007, 19:17 UTC · re: Junio C Hamano · lore

Re: ~ and ^

On Sun, 13 May 2007 12:07:21 -0700 Junio C Hamano <junkio@cox.net> wrote:

Show 6 quoted lines
> Interesting.
> 
> At least, "ls ~0" does not seem to get confused by bash to be
> the home directory of the root user, so I do not offhand think
> of a reason not to have ~$n as a synonym to HEAD~$n.  Would that
> be useful?  I dunno.

Not going to shake the world but it's a small convenience. Would be a bit nicer if a lone ~ worked as well without escaping, but I'm not sure you'd accept a patch to assume "~" whenever git is passed the users home directory as a lone option ;)

> P.S.
> 
> Welcome back to the list ;-)
> 
Thanks.
Sean
Robin Rosenberg· May 13, 2007, 20:31 UTC · re: Junio C Hamano · lore

Re: ~ and ^

söndag 13 maj 2007 skrev Junio C Hamano:
Show 14 quoted lines
> Sean <seanlkml@sympatico.ca> writes:
> 
> > Would it be possible/reasonable to treat a bare ~3 (or ^) on the git command
> > line as equivalent to "<current branch>~3" ?    At least @{3} already works
> > this way and it would be nice to do the same for the even more common tilde
> > and hat operations.  If so, it would be a small convenience to just type:
> > "git show ~3"
> 
> Interesting.
> 
> At least, "ls ~0" does not seem to get confused by bash to be
> the home directory of the root user, so I do not offhand think
> of a reason not to have ~$n as a synonym to HEAD~$n.  Would that
> be useful?  I dunno.
~0 is my current directory in bash.

$ echo ~0 /home/me/tmp

-- robin

← back to recent threads