简体   繁体   English

使用集中式工作流程进行Git版本编号

[英]Git Version numbering with a centralized workflow

We are using Git with a central server, and our code needs to include a version number in a file. 我们正在使用Git和中央服务器,我们的代码需要在文件中包含版本号。 The way this is currently done is like this: 目前这样做的方式是这样的:

  1. A new developer does a "git clone" 一个新的开发人员做了一个“git clone”
  2. In his local copy, he edits .git/hooks/pre-commit to call version.sh 在他的本地副本中,他编辑.git / hooks / pre-commit来调用version.sh

version.sh (which is included in the project root) takes a version number from "git describe" and stores it in a file. version.sh(包含在项目根目录中)从“git describe”获取版本号并将其存储在文件中。

While this works, I would like to make sure that the version number is updated even if a developer forgot to edit his pre-commit hook. 虽然这有效,但我想确保版本号更新,即使开发人员忘记编辑他的预提交钩子。

Since the server has no working copy, simply calling the (pre|post)-receive hooks there does not work, so I am wondering if there is a way to do this. 由于服务器没有工作副本,只是调用(pre | post)-receive挂钩不起作用,所以我想知道是否有办法做到这一点。

How about a hooks/update on the central repo that rejects commits without changes to the version file (named VERSION in the example below)? 中央仓库上的hooks/update如何拒绝提交而不更改版本文件(在下面的示例中命名为VERSION )?

#! /bin/bash

refname="$1"
oldrev="$2"
newrev="$3"

if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
  echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
  exit 1
fi

if [ "$refname" != "refs/heads/master" ]; then
  exit 0
fi

if diff -bq <(git show $oldrev:VERSION) \
            <(git show $newrev:VERSION) >/dev/null
then
  echo "$0: VERSION unchanged; rejecting update" >&2
  exit 1
fi

The x264 project automatically generates a version number by counting git commits in the history. x264项目通过计算历史记录中的git提交自动生成版本号。 It migrated from svn, where versions were actually called r678, for example, but someone cooked up a script to generate numbers from git. 它从svn迁移,例如版本实际上称为r678,但有人编写了一个脚本来从git生成数字。

http://git.videolan.org/?p=x264.git;a=blob;f=version.sh;hb=HEAD http://git.videolan.org/?p=x264.git;a=blob;f=version.sh;hb=HEAD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM