Get old git 1.7 基本上创建与 'git tag --merged' 命令相同的命令,用于数据库模式更新

Get old git 1.7 to basically create the same as the 'git tag --merged' command, for database schema updates

我希望协调 MySQL 数据库模式更新与对 git 的提交。

我最初的计划是用模式编号标记提交,例如,git 标记 schema19936 b6671a2c1。然后我可以 'git tag --merged' 查看标签在当前分支上是否可用,如果是,则 运行 schema19936 脚本。

很遗憾,我们仍然支持 CentOS 6,其中包括 git 1.7。 Git 1.7 在 git 标签中不包含 '--merged' 标志,所以我的操作将不再有效。

背景:我们来自颠覆,之前使用修订号作为我们的标准来查看代码是否需要模式更新。

在旧的 git 1.7 中是否有任何解决方法来基本上创建与 'git tag --merged' 命令相同的内容。或者有没有更好的方法来解决这个问题。

--merged 所做的只是测试血统,因此您可以手动执行此操作。即标记 T "is merged into" commit C if T commit C。提交的“≤”测试是通过 git merge-base --is-ancestor 实现的,并将 T 转换为它的提交 T commit 通过附加 ^{commit} 可以很容易地用 gitrevisions syntax 完成。 (如果标记 T 指向的不是提交,这将失败并向 stderr 发送一条消息。)

不幸的是,git merge-base --is-ancestor 是在 Git 1.8 中添加的。

幸运的是,the documentation 有一个 shell 脚本的文字位,显示 "old way" 通过这个 --is-ancestor 测试更好地表达了什么:

A common idiom to check "fast-forward-ness" between two commits A and B is (or at least used to be) to compute the merge base between A and B, and check if it is the same as A, in which case, A is an ancestor of B. You will see this idiom used often in older scripts.

A=$(git rev-parse --verify A)
if test "$A" = "$(git merge-base A B)"
then
    ... A is an ancestor of B ...
fi

In modern git, you can say this in a more direct way:

if git merge-base --is-ancestor A B
then
    ... A is an ancestor of B ...
fi

instead.

简单地替换旧测试,使用 T^{commit} 代替初始 A 并使用 $C(我们的测试承诺)代替 B:

A=$(git rev-parse T^{commit}) || exit 1
if test $A = "$(git merge-base A $C)"; then ...; fi