可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have cloned a remote Git repository to my laptop, then I wanted to add a tag so I ran
git tag mytag master
When I run git tag
on my laptop the tag mytag
is shown. I then want to push this to the remote repository so I have this tag on all my clients, so I run git push
but I got the message:
Everything up-to-date
And if I go to my desktop and run git pull
and then git tag
no tags are shown.
I have also tried to do a minor change on a file in the project, then push it to the server. After that I could pull the change from the server to my Desktop computer, but there\'s still no tag when running git tag
on my desktop computer.
How can I push my tag to the remote repository so that all client computers can see it?
回答1:
To push a single tag:
git push origin <tag_name>
And the following command should push all tags (not recommended):
git push --tags
回答2:
git push --follow-tags
This is a sane option introduced in Git 1.8.3:
git push --follow-tags
It pushes both commits and only tags that are both:
- annotated
- reachable (an ancestor) from the pushed commits
This is sane because:
- you should only push annotated tags to the remote, and keep lightweight tags for local development to avoid tag clashes. See also: What is the difference between an annotated and unannotated tag?
- it won\'t push annotated tags on unrelated branches
It is for those reasons that --tags
should be avoided.
Git 2.4 has added the push.followTags
option to turn that flag on by default which you can set with:
git config --global push.followTags true
回答3:
To push specific, one tag do following
git push origin tag_name
回答4:
To expand on Trevor\'s answer, you can push a single tag or all of your
tags at once.
Push a Single Tag
git push <remote> <tag>
This is a summary of the relevant documentation that explains this (some
command options omitted for brevity):
git push [[<repository> [<refspec>…]]
<refspec>...
The format of a <refspec>
parameter is…the source ref <src>
,
followed by a colon :
, followed by the destination ref <dst>
…
The <dst>
tells which ref on the remote side is updated with this
push…If :<dst>
is omitted, the same ref as <src>
will be
updated…
tag <tag>
means the same as refs/tags/<tag>:refs/tags/<tag>
.
Push All of Your Tags at Once
git push --tags <remote>
# Or
git push <remote> --tags
Here is a summary of the relevant documentation (some command options
omitted for brevity):
git push [--all | --mirror | --tags] [<repository> [<refspec>…]]
--tags
All refs under refs/tags
are pushed, in addition to refspecs explicitly
listed on the command line.
回答5:
You can push the tags like this git push --tags
回答6:
Tags are not sent to the remote repository by the git push command. We need to explicitly send these tags to the remote server by using the following command:
git push origin <tagname>
We can push all the tags at once by using the below command:
git push origin --tags
Here are some resources for complete details on git tagging:
http://www.cubearticle.com/articles/more/git/git-tag
http://wptheming.com/2011/04/add-remove-github-tags
回答7:
You can push your local tags by simply git push --tags
command.
$ git tag # see tag lists
$ git push origin <tag-name> # push a single tag
$ git push --tags # push all local tags
回答8:
I am using git push <remote-name> tag <tag-name>
to ensure that I am pushing a tag. I use it like: git push origin tag v1.0.1
. This pattern is based upon the documentation (man git-push
):
OPTIONS
...
<refspec>...
...
tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.
回答9:
Please do not use it, if you are only looking for a command because the main intention of this solution is to introduce you a way of solutions !
To make life easier - i wrote a script git-cheat-sheet ,that contains some useful commands , including the following:
./git_commands.sh -push_tag TAG_NAME
回答10:
If you are working in a branch:
git push --tags origin branch_name