当获取单个分支时,git fetch
包含指向该分支的所有标签:
When refspec stores the fetched result in remote-tracking branches, the tags that point at these branches are automatically followed. This is done by first fetching from the remote using the given s, and if the repository has objects that are pointed by remote tags that it does not yet have, then fetch those missing tags. If the other end has tags that point at branches you are not interested in, you will not get them.
有没有办法让 git push
的行为相同?手册页说明了如何不推送标签(默认)、所有标签(--tags
)或您在命令行中命名的标签。它没有提供将所有指向分支的方法推送。
最佳答案
您可以尝试使用 git1.8.3+ (2013 年 5 月):
git push --follow-tags
The new "
--follow-tags
" option tells "git push
" to push relevant annotated tags when pushing branches out.
这不会推送所有标签,而只会推送可从您推送的分支 HEAD 访问的标签。
如“Push a tag to a remote repository using Git? ”中所述,这仅涉及 annotated tags ,而不是轻量级标签。
git tag 1.0
(轻量级)不会用 --follow-tags
推送,它会用 git push --tags
。
使用 Git 2.4.1+(2015 年第 2 季度),该选项可以设置为默认值。
参见 commit a8bc269通过 Dave Olszewski (cxreg
) :
make it easier to add new configuration bits and then add
push.followTags
configuration that turns--follow-tags
option on by default.
文档将包括:
push.followTags::
If set to true enable '
--follow-tags
' option by default. You may override this configuration at time of push by specifying '--no-follow-tags
'
请全局启用此设置,您可以运行 git config --global push.followTags true
。它也可以在每个存储库的基础上指定。
关于git - 如何使 "git push"在分支中包含标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17219102/