How to overwrite local tags with git fetch? I want to replace local tags with remote tags.
问题:
回答1:
git fetch --tags
will do it.
From the docs (description of the --tags
parameter):
Most of the tags are fetched automatically as branch heads are downloaded, but tags that do not point at objects reachable from the branch heads that are being tracked will not be fetched by this mechanism. This flag lets all tags and their associated objects be downloaded. The default behavior for a remote may be specified with the remote..tagopt setting.
回答2:
As of Git 2.2.0 you need to explicitly specify the force flag:
git fetch origin --tags --force
Until Git version 2.20, and unlike when pushing with git-push[1], any updates to refs/tags/* would be accepted without + in the refspec (or --force). When fetching, we promiscuously considered all tag updates from a remote to be forced fetches. Since Git version 2.20, fetching to update refs/tags/* works the same way as when pushing. I.e. any updates will be rejected without + in the refspec (or --force).
https://git-scm.com/docs/git-fetch
回答3:
git fetch --tags --all --prune
This will explicitly tell git to fetch, and at the same time, remove tags which no longer exist on the remote.
回答4:
First, unlike for branches, git does not track remote tags different from local tags. Once finished fetching, they are indistinguishable.
- does update the local tag (even though the manual doesn’t tell)
git fetch --tags
- does not update the local tag
git fetch
git fetch --prune
git fetch --prune --force
A tag update/overwrite looks like this:
From git:path/name
- [tag update] my_tag -> my_tag
This works for lightweight and annotated tags, even mixed. That is: an annotated tag might be overwritten with a lightweight one and vice versa.
I used git version 2.7.4
回答5:
Tags won't be overwritten, because they are meant to be sort-of immutable. If you want to have an object that is (realistically) changable, use a branch pointer or a ref instead. That leaves you with: git tag -d tagname..., and then fetching it again.