Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git-describe prefix the commit ID with the letter 'g'?

Tags:

git

Typical output of git-describe looks like

some-tag-32-gf31f980 

where some-tag is a tag name, 32 means that the described commit is 32 commits after the commit with that tag, and gf31f980 means that the commit ID is uniquely abbreviated to f31f980.

My question is about the g in gf31f980. Why is it there? My first thought was that it is inserted to disambiguate parsing of the output of git-describe. But I can't think of any case in which it actually helps to have it. For example, the 32 component might be omitted, and there is no way to know that the output above describes a commit 32 commits after the tag some-tag, rather than the commit at the tag some-tag-32. But the g doesn't help with this.

A regex match to extract just the commit ID can search for /-g([0-9a-f]+)$/. There is no easy way to simplify this; you can't do /-g(.*)$/ for example because that might erroneously match a g in the tag name. Without the g you could still do /-([0-9a-f]+)$/, so the g isn't helping you there. Non-regex parsing processes will behave similarly.

The g is generated explicitly; the relevant source code (around line 240 of builtin/describe.c) is:

static void show_suffix(int depth, const unsigned char *sha1) {         printf("-%d-g%s", depth, find_unique_abbrev(sha1, abbrev)); } 

It's hard to search for information about this, because the relevant term, g, is a stopword.

What's the g for?

like image 458
Mark Dominus Avatar asked May 29 '14 17:05

Mark Dominus


People also ask

What is the commit ID in git?

Commit IDs are unique SHA-1 hashes that are created whenever a new commit is recorded. If you specify a commit ID when you add a repository, Domino will always pull the state of the repository specified by that commit in a detached HEAD state.

What is git describe -- tags?

The `git describe` command finds the most recent tag that is reachable from a commit. If the tag is on the current commit, then only the tag is shown. Otherwise, it shows the tag name appended with the number of additional commits and the abbreviated SHA of the current commit.

Where is the commit ID in GitHub?

If you are unsure of the value to type: In a different web browser tab, go to your GitHub dashboard . In Your repositories, choose the repository name that contains the target commit. In the list of commits, find and copy the commit ID that refers to the revision in the repository.


1 Answers

Jesse Luehrs immediately pointed out on Twitter that this question is answered in the git-describe man page:

The "g" prefix stands for "git" and is used to allow describing the version of a software depending on the SCM the software is managed with.

like image 138
2 revs, 2 users 86% Avatar answered Sep 25 '22 19:09

2 revs, 2 users 86%