TIMEX
TIMEX

Reputation: 272164

In Git, how do I figure out what my current revision is?

I just want to know what my current revision number is.

Upvotes: 214

Views: 279960

Answers (6)

John.M
John.M

Reputation: 363

For a simple way to output the current commit that includes the version number, I use:

git show $(git rev-parse HEAD)

From there I can parse the output as required.

Upvotes: 0

William Pursell
William Pursell

Reputation: 212484

What do you mean by "version number"? It is quite common to tag a commit with a version number and then use

$ git describe --tags

to identify the current HEAD w.r.t. any tags. If you mean you want to know the hash of the current HEAD, you probably want:

$ git rev-parse HEAD

or for the short revision hash:

$ git rev-parse --short HEAD

It is often sufficient to do:

$ cat .git/refs/heads/${branch-main}

but this is not reliable as the ref may be packed.

Upvotes: 300

Ken McConnell
Ken McConnell

Reputation: 199

This gives you the first few digits of the hash and they are unique enough to use as say a version number.

git rev-parse --short HEAD

Upvotes: 19

Alexey Bychko
Alexey Bychko

Reputation: 71

below will work with any previously pushed revision, not only HEAD

for abbreviated revision hash:

git log -1 --pretty=format:%h

for long revision hash:

git log -1 --pretty=format:%H

Upvotes: 4

htanata
htanata

Reputation: 36954

This gives you just the revision.

git rev-parse HEAD

Upvotes: 49

manojlds
manojlds

Reputation: 301347

There are many ways git log -1 is the easiest and most common, I think

Upvotes: 127

Related Questions