With git describe
you can get the number of commits since the last tag. If you only had the tag and the number of commits what is the best way to show the commit that was described?
I know you could use git log tag..
and pipe it to a a script that does the counting but I was hoping for a more elegant solution similar to git show tag~n
.
To add more context, we are planning using git describe
to create release numbers, for example with
$ git describe v1.5-39-g5ede964
we would use foo_1.5.39. What we would like to do is knowing 1.5.39 means the 39th commit after the v1.5 tag, find that commit, i.e. find g5ede964. As pointed out in a comment, the 39th commit after v1.5 may not be unique. So perhaps a better way to ask this is what is the best way to find all commits X such that if HEAD was pointing to X git describe
would return v1.5-39-*****
.
The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first.
`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.
By default, git-show acts against the HEAD reference. The HEAD reference always points to the last commit of the current branch. Therefore, you can use git-show to display the log message and diff output of the latest commit.
Try
git rev-list tag..HEAD --count
OR
git rev-list tag.. --count
They mean the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With