如何在git commit上引入make依赖?

时间:2016-03-01 02:30:41

标签: git makefile git-commit

我制作了一个小脚本,生成一个标题,其中包含我的存储库的git提交信息,我可以在我的源代码中包含该脚本,以查看我正在使用的代码版本。例如:

#if !defined physicsplay_build_version_h_is_included
#define physicsplay_build_version_h_is_included

#define PHYSICSPLAY_COMMIT_INFO "Revision https://github.com/peeterjoot/physicsplay commit d771eeced6552643b3f08c8f87286494189a72a8 Feb/29/2016"

#endif

如果我已经完成了新的提交,我想写一个make规则来重新生成这个文件。我尝试在我的makefile中使用.git / index作为此头文件的依赖项,但是在' git status'之后会更新。可能还有其他的事情。

引入此类make依赖项的最佳方式是什么?

1 个答案:

答案 0 :(得分:2)

  

如果我已经完成了新的提交,我想写一个make规则来重新生成这个文件

使用挂钩:pre-commitpre-recive

hook sample

#!/bin/sh

# Check to see if this is the first commit in the repository or not
if git rev-parse --verify HEAD >/dev/null 2>&1
then
    # We compare our changes against the previous commit
    against=HEAD^
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# Redirect output to screen.
exec 1>&2

# Check and do what ever you want to do here
if [ ...  ];
then

    # personal touch :-)
    echo "                                         "
    echo "                   |ZZzzz                "
    echo "                   |                     "
    echo "                   |                     "
    echo "      |ZZzzz      /^\            |ZZzzz  "
    echo "      |          |~~~|           |       "
    echo "      |        |-     -|        / \      "
    echo "     /^\       |[]+    |       |^^^|     "
    echo "  |^^^^^^^|    |    +[]|       |   |     "
    echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
    echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
    echo "  |       |  []   /^\   []   |+[]+   |   "
    echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
    echo "  |[]+    |      || ||       |[]+    |   "
    echo "  |_______|------------------|_______|   "
    echo "                                         "
fi;

# set the exit code to 0 or 1 based upon your needs
# 0 = good to push
# 1 = exit without pushing.
exit 0;