Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

People also ask

What is a git revision?

So "revision" refers to the id you can use as a parameter to reference an object in git (usually a commit).

What is current head in git?

When working with Git, only one branch can be checked out at a time - and this is what's called the "HEAD" branch. Often, this is also referred to as the "active" or "current" branch. Git makes note of this current branch in a file located inside the Git repository, in .

What is the git command for displaying the list of previous revisions?

Don't worry, Git has got you covered! By running git log -p , you'll get the same list as before, however each commit will have a list of the files that have been added/modified/removed, as well as the actual changes themselves.


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.


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


This gives you just the revision.

git rev-parse HEAD

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

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