# ~ and ^

6 messages from 2007-05-13 to 2007-05-13. Participants: Sean, Junio C Hamano, Karl Hasselström, Robin Rosenberg.
Thread: https://gitlist.dev/t/8135

## Sean, 2007-05-13 18:44

Subject: ~ and ^
Message-ID: <20070513144442.b3cba792.seanlkml@sympatico.ca>
URL: https://gitlist.dev/e/20070513144442.b3cba792.seanlkml%40sympatico.ca

```

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, 2007-05-13 19:07

Subject: Re: ~ and ^
Message-ID: <7v8xbssfti.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v8xbssfti.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070513144442.b3cba792.seanlkml@sympatico.ca>

```
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.

P.S.

Welcome back to the list ;-)

```

## Karl Hasselström, 2007-05-13 19:13

Subject: Re: ~ and ^
Message-ID: <20070513191350.GB14657@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20070513191350.GB14657%40diana.vm.bytemark.co.uk
In-Reply-To: <7v8xbssfti.fsf@assigned-by-dhcp.cox.net>

```
On 2007-05-13 12:07:21 -0700, Junio C Hamano wrote:

> 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, 2007-05-13 19:17

Subject: Re: ~ and ^
Message-ID: <20070513151709.76b5fc33.seanlkml@sympatico.ca>
URL: https://gitlist.dev/e/20070513151709.76b5fc33.seanlkml%40sympatico.ca
In-Reply-To: <7v8xbssfti.fsf@assigned-by-dhcp.cox.net>

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

> 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

```

## Sean, 2007-05-13 19:49

Subject: Re: ~ and ^
Message-ID: <20070513154905.36da94e1.seanlkml@sympatico.ca>
URL: https://gitlist.dev/e/20070513154905.36da94e1.seanlkml%40sympatico.ca
In-Reply-To: <20070513191350.GB14657@diana.vm.bytemark.co.uk>

```
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

```

## Robin Rosenberg, 2007-05-13 20:31

Subject: Re: ~ and ^
Message-ID: <200705132231.03180.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200705132231.03180.robin.rosenberg.lists%40dewire.com
In-Reply-To: <7v8xbssfti.fsf@assigned-by-dhcp.cox.net>

```
söndag 13 maj 2007 skrev Junio C Hamano:
> 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

```
