代码之家  ›  专栏  ›  技术社区  ›  Arthur Ulfeldt

从git存储库派生版本号

  •  2
  • Arthur Ulfeldt  · 技术社区  · 14 年前

    3 回复  |  直到 14 年前
        1
  •  2
  •   Cascabel    14 年前

    你在找什么 git describe :

    可从提交访问的。如果 仅显示标记。否则,它 在 标记对象和缩写 最近提交的对象名称。

    $ git describe master
    v1.10-5-g4efc7e1
    
        2
  •  2
  •   peritus    14 年前

    git描述 如前所述,这里是我的rake任务,它打印出递增的结果 semver compliant version numbers 自动:

    task :version do
      git_describe = `git describe --dirty --tags --match 'v*'`
    
      version, since, sha, dirty = git_describe.strip.split("-")
      major, minor, patch = version.split(".")
    
      version = "#{major}.#{minor}.#{patch}"
    
      if sha
        patch = String(Integer(patch) + 1)
        version = "#{version}pre#{since}-#{sha[1..sha.length]}"
      end
    
      if [since, dirty].include?("dirty")
         version = "#{version}-dirty"
      end
    
      puts version
    
    end
    

    用法如下:

    $> rake version

    v0.9.8pre32-fcb661d

        3
  •  0
  •   Jason Jenkins    14 年前

    在git中,每次提交都会生成一个唯一的SHA1哈希id。运行时可以看到每次提交的id git log git log --pretty=oneline --abbrev-commit --abbrev=5 -1 . 对于我的一个回购,输出如下所示:

    $ git log --pretty=oneline --abbrev-commit --abbrev=5 -1    
    3b405... fixed css for page title.
    

    你可以尝试其他的方法 git日志 根据需要自定义格式。当然,如果存储库有足够的提交,那么5位数字总是不足以保证唯一性的,但是对于足够小的项目,它可以做到。