Andrew Kim
Andrew Kim

Reputation: 3335

What is the name of pointers like `HEAD~1` in git?

I'm aware that HEAD~1 represents the parent of the commit HEAD is on and that HEAD^2 represents the second parent of the commit HEAD is on.

From git reflog, HEAD@{n} is a gitrevision.

Do pointers like HEAD~n, HEAD^n, HEAD~3^2, master~1, cb2510e~1 etc. have a special name? Are they references in the same way that branches point to a specific commit? Is it called a relative reference?

I've been trying to look, but have not been successful. Can anyone shed some light?

Upvotes: 2

Views: 501

Answers (4)

user12801366
user12801366

Reputation: 1

I tried to find out about that extended SHA-1 syntax --- but that seems to be a git thing. Maybe this is even meant with a grain of humour: the "canonical" name would be the (abrrev.) SHA-1 name. But for practical reasons you have HEAD (and @) and this extended (a bit cryptic) syntax.

"SPECIFYING REVISIONS" is the big title in gitrevisions.

A revision parameter <rev> typically, but not necessarily, names a commit object. It uses what is called an extended SHA-1 syntax. Here are various ways to spell object names. The ones listed near the end of this list name trees and blobs contained in a commit.

So HEAD~1 would be a name for (= a way to spell) a commit object, whose (real) name is "7ah25e...".

Upvotes: 0

jthill
jthill

Reputation: 60275

A name I saw used for them which stuck with me is "revspec" which does pair nicely with "refspec", the pairing used to describe how fetch and push should map refnames in the different repositories. I don't recall where I saw it and I don't recall ever using it, a git grep on the source says it only occurs in the sample post-receive hook, googling says others do use it.

Upvotes: 0

torek
torek

Reputation: 488103

I would say that all of these are, collectively, "git revisions" (or gitrevisions as one word). Note that all of these are listed in the gitrevisions documentation.

Unfortunately, this term also seems to encompass range notations such as origin/master..master. For discussion purposes we would like to have a term that is specific to the two halves of such an expression, so as to construct a formal grammar. Git does not define one, so you must invent your own. The closest seems to be the phrase extended SHA-1 syntax, as jsageryd noted. This is a particularly poor term: despite its clumsiness, it's too specific, given that there is a long term effort to move Git from SHA-1 to some other hashing algorithm.

Internally, within the source to Git, there is a move to rename these to OID, which stands for Object IDentifier. OID seems like the most appropriate term. However, internally, this is for the fully resolved thing that is currently a 160-bit SHA-1 and will eventually be larger. Perhaps extended OID? :-)

Upvotes: 1

jsageryd
jsageryd

Reputation: 4633

A term used both in man gitrevisions and in commit messages in the Git project is "extended SHA-1 syntax".

Although, I am inclined to think that its usage is for the most part limited to technical discussions about Git internals. I may be wrong.

Upvotes: 0

Related Questions