Is there any way how to refer to latest git commit in a repository (regardles of a branch)?
We are moving from mercurial to git. One of our CI integration tests verifies latest commit to a specific repo. It uses the tip tag to retrieve it (it downloads a .zip from Bitbucket cloud using the 'tip.zip' reference). Now I'm wondering if this is achievable in git without need to sync the repo (there are internal reasons why the test uses zip download instead of checkout/sync).
Mercurial's tip is simply the last modified head in the repository. This works because Mercurial numbers each commit as it goes into the repository. This number is not useful in any clone of the repository as the same commit(s) might be in the clone but might have arrived in a different order, or arrived after some other commit that is in that other repository (that is not in this one) got in.1
Taking the most recently incorporated, and therefore numerically last, commit in a Mercurial repository is not a good way to work, because the commit that just went in a moment ago might be on some sort of test or backup branch that has nothing to do with the real work people are doing. You should instead be taking a specific latest commit—the latest proposed-for-inclusion-in-release, or latest-for-development, or whatever.2 (You can get this easily in both Mercurial and Git.)
In any case, Git simply has no notion of "latest in repository". Each branch name in Git defines the latest commit in that branch, so "tip of develop
" or "tip of master
" or whatever is simply "the commit identified by that name". Whether and how you can download a zip file of those commits is up to your hosting provider, but git archive
makes this easy, so chances are very good that you can easily do the right thing. Don't even try to do the wrong thing, which Git doesn't provide.
1Note that the name tip
in any other clone will name its highest-numbered revision. If the same changesets both just went in to both repositories, they may have different local numbers, but the last one will have the highest local number. In this particular case, then, tip
in each repository would name the same changeset.
See also the Mercurial FAQ, under the definitions of "head" and "tip". Note how each changeset has two numbers: a local, simple incrementing count, and a hash ID: 0:838e
, 1:3fe4
, 2:4563
, and so on. Git has the hash ID, but not the locally-useful, incrementing and easy-to-use number. Git thus forces you to use a raw hash ID, or a branch name.
(I'm not sure how tip
plays with the Hg Evolve extension. I imagine it still just refers to the highest local revision number, since you would outdate an old head by inserting a new head. This would maintain the property that the Mercurial tip is always a head, although not all Mercurial heads are the tip—only one head can be the tip.)
2You also run the risk of someone else delivering new commits to the repository while you're not looking, so that either tip
or a branch name refers to an even-newer commit than the one you intended. Ideally, you want a unique unchanging identifier for a commit. That would be its hash ID. You can use a hash ID in both VCSes, but hash IDs are, at the least, annoying. This risk may be outweighed by the convenience of names.