Since I created my repository it appears that the tags I have been
creating are not pushed to the repository. When I do git tag
on the
local directory开发者_StackOverflow中文版 all the tags are present, but when I logon to the
remote repository and do a git tag
, only the first few show up.
What could the problem be?.
You could do this:
git push --tags
In default git remote configuration you have to push tags explicitly (while they are fetched automatically together with commits they point to). You need to use
$ git push <remote> tag <tagname>
to push a single tag, or
$ git push <remote> --tags
to push all tags (or git push --tags
to push to default remote, usually origin
).
This is very much intended behavior, to make pushing tags explicit. Pushing tags should be usually conscious choice.
Summarizing what Junio C. Hamano wrote (linked in comments by @Andre Miras)
When fetching, you are interacting with a remote repository somebody has published, which means:
- the set of tags that exist there are all the publisher wanted people to see, and
- not only you but other people will also see the same tags.
In other words, tags in repositories you fetch from are designed to be public and shared. It will facilitate communication between developers if it is easy for everybody to fetch these same tags.
That's why git fetch
automatically "follows" tags, i.e. it downloads tags when downloading revisions they point to - in other words downloads all relevant published tags.
When pushing, you are pushing from your working repository, which most of the time is not public, and tags in that repository is not designed to be public. You can use your own local tags to mark your progress, so it does not make sense to blindly push all tags in your repository to the repository you are pushing to publish your changes, whose tags are by definition public.
That's why you need to push tag explicitly, to mark tag as public.
Alternatively you can configure the remote you push to to always push all tags, e.g. put something like that in your .git/config
:
[remote "publish"] # or whatever it is named url = ... push = +refs/heads/*:refs/heads/* push = +refs/tags/*:refs/tags/*
This means force push all heads (all branches) and all tags (if you don't want force pushing of heads, remove '+' prefix from refspec).
Note that since git 1.8.3 (April 22d, 2013), you no longer have to do 2 commands to push branches, and then to push tags:
The new "
--follow-tags
" option tells "git push
" to push relevant annotated tags when pushing branches out.
You can now try, when pushing new commits:
git push --follow-tags
That won't push all the local tags though, only the annotated ones referenced by commits which are pushed with the git push
.
This has been introduced in commit c2aba15 by Junio C Hamano (gitster
):
The new option "
--follow-tags
" tells "git push
" to push annotated tags that are missing from the other side and that can be reached by the history that is otherwise pushed out.For example, if you are using the "
simple
", "current
", or "upstream
" push, you would ordinarily push the history leading to the commit at your currentHEAD
and nothing else.
With this option, you would also push all annotated tags that can be reached from that commit to the other side.
The config push.followTags
allows to include --follow-tags
by default (Git 2.4.1+, Q2 2015).
See "Push git commits & tags simultaneously"
What I usually do is :
[remote "publish"] # or whatever it is named url = ... push = : push = +refs/tags/*:refs/tags/*
Meaning it pushes every branch that's already there, plus tags. It does not force push, and it does not push branch that you didn't push manually.
And if you want to force fetch all the tags, you may set it in the config by:
git config remote.origin.tagopt --tags
From the docs:
Setting this value to --no-tags disables automatic tag following when fetching from remote . Setting it to --tags will fetch every tag from remote , even if they are not reachable from remote branch heads. Passing these flags directly to git-fetch(1) can override this setting. See options --tags and --no-tags of git-fetch(1).
精彩评论