5

I am working on a "big" project, and it has several tags.

Regularly, tarballs are generated and saved with the last hash in their name (not the best practice, but it's how it rolls).

The following need has risen: We would like to download from our server the tarball identified for tags/v1.0.0.

The question is now: how can I get the hash of that tag without cloning the whole project?

EDIT (OP): The question was unclear. I do not want to download the project, as it is big, and the only piece of information I want is the hash of the tag.

5
  • So you want to checkout a commit at a particular tag? You don't need the hash, you can just checkout the tag directly
    – Liam
    Commented Jan 15, 2018 at 10:53
  • @Liam No, checking out a tag means cloning the full history leading up to that tag. That's not what's asked here.
    – user743382
    Commented Jan 15, 2018 at 11:14
  • So what did you ask here? You just want the hash? Why? If you want something that's checked into the repo you need to update the repo. You can't access individual files inside the repo without updating it whether you have the hash or not
    – Liam
    Commented Jan 15, 2018 at 11:16
  • I don't want a copy of the whole project on my machine. I only want to access the hash of a tag. Is the only way to do so to checkout / clone the remote project ?
    – fzd
    Commented Jan 15, 2018 at 11:45
  • @Liam Unless you have a copy of the code, accessible by hash, external to Git. Which is exactly what the OP has and was already specified in the question in its very first revision.
    – user743382
    Commented Jan 15, 2018 at 12:04

1 Answer 1

3

When you are trying to get some information you can use ls-remote.

In your scenario you would do the command:

git ls-remote <remote> refs/tags/v1.0.0

This will output something along the lines of:

e8b29c3c46a59dc59e2a3b22c253860c23a9ea39 refs/tags/v1.0.0

which you should be able to mangle into something useful :)

<remote> is the remote that you are querying. A complete example with another reference to get the sha of the master branch would be:

git ls-remote ssh://[email protected]/praqma-training/gitkatas refs/heads/master

with output:

634c33168ee434a10f74e3254c3f5f548f263250 refs/heads/master.

Good luck!

1
  • Excellent. Does exactly what I expected !
    – fzd
    Commented Jan 15, 2018 at 12:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.