惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
J
Java Code Geeks
博客园 - 聂微东
量子位
C
Check Point Blog
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
B
Blog
罗磊的独立博客
腾讯CDC
GbyAI
GbyAI
博客园 - 【当耐特】
A
About on SuperTechFans
M
MIT News - Artificial intelligence
U
Unit 42
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队

vivaxy's Blog

SameSite Cookies 解读 - vivaxy's Blog VSCode Conventional Commits 插件 - vivaxy's Blog VSCode Conventional Commits Extension - vivaxy's Blog How Babel Is Built - vivaxy's Blog 一步一步解码 PNG 图片 - vivaxy's Blog Babel 的工程化实现 - vivaxy's Blog 浏览器图像转换手册 - vivaxy's Blog Decoding A PNG Image with JavaScript Step by Step Comprehensive Image Processing on Browsers Use npm Registry to Restric Installing Client Alfred 4 Workflow Open in VSCode 基于 Custom Elements 的组件化开发 - vivaxy's Blog JavaScript PNG 图片编码和解码 - vivaxy's Blog 如何在多个模块中共享异步数据 - vivaxy's Blog JavaScript 函数式编程初窥 - vivaxy's Blog 用纯 CSS 实现弹窗 - vivaxy's Blog 在浏览器中使用 JavaScript 模块 - vivaxy's Blog Karabiner Elements Hyper 改键设置 - vivaxy's Blog Levenshtein 距离 - vivaxy's Blog Levenshtein 距离 - vivaxy's Blog
Git Tag And Push Git Tag
vivaxy · 2019-08-02 · via vivaxy's Blog
  • Why my git tags cannot be pushed sometimes?
  • What’s the difference between git push --follow-tags and git push --tag?

There are concepts beneath the questions. Firstly, We will talk about lightweight tag and annotated tag.

Lightweight Tag And Annotated Tag.

Quote from Git - Tagging

Git supports two types of tags: lightweight and annotated.

A lightweight tag is very much like a branch that doesn’t change — it’s just a pointer to a specific commit.

Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have all this information; but if you want a temporary tag or for some reason don’t want to keep the other information, lightweight tags are available too.

As we can see, annotated tags are the tags that matter. They should be taking good care of.

How To Tag?

git tag <tagname>                 => lightweight tag
git tag -a <tagname>              => annotated tag, will prompt for mesage
git tag -a -m <msg> <tagname>     => annotated tag
git tag -m <msg> <tagname>        => annotated tag

What Does npm version Do?

npm version will tag package versions like this:

Quote from cli/version.js · npm/cli

// ...
const flagForTag = signTag ? '-sm' : '-m'
// ...
stagePackageFiles(localData, options).then(() => {
  return git.exec(commitArgs, options)
}).then(() => {
  if (!localData.existingTag) {
    return git.exec([
      'tag', npm.config.get('tag-version-prefix') + version,
      flagForTag, message
    ], options)
  }
}).nodeify(cb)
// ...

It is an annotated tag.

So How Do We Push Tags?

There are two ways of pushing tags:

  • git push --follow-tags
  • git push --tags

Quote from How do you push a tag to a remote repository using Git? - Stack Overflow

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:

It is for those reasons that –tags should be avoided.

How do we push tags? git push --follow-tags!

In Conclusion

When you can’t push tags, you probably:

  • are using a lightweight tag, and git push --follow-tags.

While you can push tags, you probably:

  • are using a lightweight tag, and git push --tags. (Not recommended!)
  • are using an annotated tag, and git push --follow-tags.

Reference