sakshi
sakshi

Reputation: 293

How to check latest revision number of a file in git?

I am trying to understand the comparison between clearcase, subversion and git revisioning. I am not able to understand the revisioning mechanism of git.How can we get the latest revision number of a file in git?

Upvotes: 1

Views: 3088

Answers (3)

uday
uday

Reputation: 8710

Everything in Git is check-summed before it is stored and is then referred to by that checksum. The mechanism that Git uses for this checksumming is called a SHA-1 hash. So you need to look for the latest SHA-1 hash on that file to get the latest revision number.

To list all the commits on file just do git log <filename>

To get the latest commit on a particular file do: git log -n 1 <filename>

Hope it helps!

Upvotes: 3

user743382
user743382

Reputation:

Git doesn't use revision numbers. It identifies commits by their hash, which is presented to you as a 40-character string of digits and letters by various commands, including git log.

However, keep in mind that Git also effectively tracks each branch independently. You can get the last commit in e.g. svn by just getting the highest number. That doesn't work in Git. If you want the latest commit in all branches (something you typically don't need, but a question that's nonetheless asked often enough), you have to actually inspect all branches. git log --all, or git log <branch1> <branch2> <branch3> <...> to be explicit, will show the most recent commit across all those branches as the first one.

Upvotes: 1

Pubudu Perera
Pubudu Perera

Reputation: 84

Here's the command.

git log -n 1 <file>

Upvotes: 2

Related Questions