简体   繁体   中英

How to do `git log` or `git describe` for remote tags?

I can do this for local branches and tags:

git log some-branch
git describe some-branch
git log some-tag
git describe some-tag

But I can't figure out how to do the same for remote tags. It works fine for branches:

git log origin/some-branch
git describe origin/some-branch

so by analogy I'm trying this:

$ git log origin/some-tag

fatal: ambiguous argument 'origin/some-tag': unknown revision or path not in the working tree.

$ git describe origin/some-tag

fatal: Not a valid object name origin/some-tag

I also tried replacing origin with origin/refs/tags , but that doesn't work either. Is there a way to make it work?

I'd like to avoid checking out the tags locally because I'm creating an automated tool that creates a lot of its own branches, so it would get messy or it'd require cleanup after finishing which might not run if something goes wrong, so I'm trying to avoid extra complexity. It seems like it should be achievable similarly to git log origin/... , I just don't know how.

You cannot directly interact with remote branches or tags. You have to fetch them first.

In addition to branches and tags, git has several other types of ref. One of those is the "remote tracking ref". In a normal configuration, these are updated each time you fetch from the remote to show where the remote branch pointed at that time. That is what you are using when you say git log origin/branch .

So when you say git log origin/branch , that does not generate a log of where branch is on the remote. It generates a log of where the remote branch was the last time you updated the local repo from the remote.

Because tags are not expected to move, there is not a corresponding concept of "remote tracking refs for tags".[1]

The correct way is to fetch and then log

git fetch origin
git log origin/branch

(Since you just fetched, this will reflect anything in the remote except if someone pushes at basically the same time.)

git fetch origin --tags
git log some-tag

[1] Through configuration there is actually a lot of flexibility for how refs (including tags) are mapped from the origin. You could create your own convention for naming "tags as I fetched them from the remote", in order to distinguish them from tags created locally. There are details that you'd have to get right, and again there's generally so little value (since tags shouldn't moev) that git itself didn't bother, so I suspect you'd find it to just be too much trouble; but if you really want to, you can.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM