git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Is current HEAD pointing at a given revision ?
@ 2011-06-14  6:59 Francis Moreau
  2011-06-14  9:00 ` Jakub Narebski
  0 siblings, 1 reply; 5+ messages in thread
From: Francis Moreau @ 2011-06-14  6:59 UTC (permalink / raw)
  To: git

Hello,

I have a given revision (tag, sha1 ...) and I'd like to know if that
revisions corresponds to what the current HEAD is pointing at.

Could anybody give me some advices for achieving this ?

Thanks
-- 
Francis

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

* Re: Is current HEAD pointing at a given revision ?
  2011-06-14  6:59 Is current HEAD pointing at a given revision ? Francis Moreau
@ 2011-06-14  9:00 ` Jakub Narebski
  2011-06-14 15:56   ` Francis Moreau
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Narebski @ 2011-06-14  9:00 UTC (permalink / raw)
  To: Francis Moreau; +Cc: git

Francis Moreau <francis.moro@gmail.com> writes:

> I have a given revision (tag, sha1 ...) and I'd like to know if that
> revisions corresponds to what the current HEAD is pointing at.
> 
> Could anybody give me some advices for achieving this ?

If you want to know if given revision (or ref) points at the same
thing as HEAD, you can use

  [ "$(git rev-parse HEAD)" = "$(git rev-parse $ref^{commit})" ]

or something like that.  The '^{commit}' is here in case $ref points
only indirectly to commit, via a tag object.

If you want to kow if current HEAD is tagged, you can use instead

  git describe --exact-match HEAD

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

* Re: Is current HEAD pointing at a given revision ?
  2011-06-14  9:00 ` Jakub Narebski
@ 2011-06-14 15:56   ` Francis Moreau
  2011-06-14 16:17     ` Jakub Narebski
  0 siblings, 1 reply; 5+ messages in thread
From: Francis Moreau @ 2011-06-14 15:56 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

On Tue, Jun 14, 2011 at 11:00 AM, Jakub Narebski <jnareb@gmail.com> wrote:
> Francis Moreau <francis.moro@gmail.com> writes:
>
>> I have a given revision (tag, sha1 ...) and I'd like to know if that
>> revisions corresponds to what the current HEAD is pointing at.
>>
>> Could anybody give me some advices for achieving this ?
>
> If you want to know if given revision (or ref) points at the same
> thing as HEAD, you can use
>
>  [ "$(git rev-parse HEAD)" = "$(git rev-parse $ref^{commit})" ]
>
> or something like that.  The '^{commit}' is here in case $ref points
> only indirectly to commit, via a tag object.
>

I see thanks.

I'm not sure what the ^{commit} is for because in the case of tag
object, git-rev-parse seems to work fine without the suffix:

git rev-parse v2.6.39
8b0753a3df28c21b0570fa21362c5f1b3b4f59bf

This is in a kernel git repository

Thanks
-- 
Francis

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

* Re: Is current HEAD pointing at a given revision ?
  2011-06-14 15:56   ` Francis Moreau
@ 2011-06-14 16:17     ` Jakub Narebski
  2011-06-14 19:17       ` Francis Moreau
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Narebski @ 2011-06-14 16:17 UTC (permalink / raw)
  To: Francis Moreau; +Cc: git

Francis Moreau wrote:
> On Tue, Jun 14, 2011 at 11:00 AM, Jakub Narebski <jnareb@gmail.com> wrote:
> > Francis Moreau <francis.moro@gmail.com> writes:
> >
> > > I have a given revision (tag, sha1 ...) and I'd like to know if that
> > > revisions corresponds to what the current HEAD is pointing at.
> > >
> > > Could anybody give me some advices for achieving this ?
> >
> > If you want to know if given revision (or ref) points at the same
> > thing as HEAD, you can use
> >
> >  [ "$(git rev-parse HEAD)" = "$(git rev-parse $ref^{commit})" ]
> >
> > or something like that.  The '^{commit}' is here in case $ref points
> > only indirectly to commit, via a tag object.
> >
> 
> I see thanks.
> 
> I'm not sure what the ^{commit} is for because in the case of tag
> object, git-rev-parse seems to work fine without the suffix:
> 
> git rev-parse v2.6.39
> 8b0753a3df28c21b0570fa21362c5f1b3b4f59bf
> 
> This is in a kernel git repository

But that is the SHA-1 id of a _tag object_, not of commit (revision)
it points to. '^{}' means peel to not tag, '^{commit}' means peel to
commit.

In git repository:

 $ git rev-parse v1.7.5
 4d2f8aeba22578022e2d2a56dac37fcdf78d82d4
 $ git rev-parse v1.7.5^{}
 ec014eac0e9e6f30cbbca616090fa2ecf74797e7
 $ git rev-parse v1.7.5^{commit}
 ec014eac0e9e6f30cbbca616090fa2ecf74797e7
 $ git cat-file -t 4d2f8aeba22578022e2d2a56dac37fcdf78d82d4
 tag
 $ git cat-file -t ec014eac0e9e6f30cbbca616090fa2ecf74797e7
 commit

 $ git cat-file -t HEAD
 commit

-- 
Jakub Narebski
Poland

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

* Re: Is current HEAD pointing at a given revision ?
  2011-06-14 16:17     ` Jakub Narebski
@ 2011-06-14 19:17       ` Francis Moreau
  0 siblings, 0 replies; 5+ messages in thread
From: Francis Moreau @ 2011-06-14 19:17 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

On Tue, Jun 14, 2011 at 6:17 PM, Jakub Narebski <jnareb@gmail.com> wrote:
> Francis Moreau wrote:
>> On Tue, Jun 14, 2011 at 11:00 AM, Jakub Narebski <jnareb@gmail.com> wrote:
>> > Francis Moreau <francis.moro@gmail.com> writes:
>> >
>> > > I have a given revision (tag, sha1 ...) and I'd like to know if that
>> > > revisions corresponds to what the current HEAD is pointing at.
>> > >
>> > > Could anybody give me some advices for achieving this ?
>> >
>> > If you want to know if given revision (or ref) points at the same
>> > thing as HEAD, you can use
>> >
>> >  [ "$(git rev-parse HEAD)" = "$(git rev-parse $ref^{commit})" ]
>> >
>> > or something like that.  The '^{commit}' is here in case $ref points
>> > only indirectly to commit, via a tag object.
>> >
>>
>> I see thanks.
>>
>> I'm not sure what the ^{commit} is for because in the case of tag
>> object, git-rev-parse seems to work fine without the suffix:
>>
>> git rev-parse v2.6.39
>> 8b0753a3df28c21b0570fa21362c5f1b3b4f59bf
>>
>> This is in a kernel git repository
>
> But that is the SHA-1 id of a _tag object_, not of commit (revision)
> it points to. '^{}' means peel to not tag, '^{commit}' means peel to
> commit.
>

Oh I see now, thanks a lot !

-- 
Francis

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

end of thread, other threads:[~2011-06-14 19:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-14  6:59 Is current HEAD pointing at a given revision ? Francis Moreau
2011-06-14  9:00 ` Jakub Narebski
2011-06-14 15:56   ` Francis Moreau
2011-06-14 16:17     ` Jakub Narebski
2011-06-14 19:17       ` Francis Moreau

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 NNTP newsgroup(s).