Follow Excellent, Success will Chase you

0%

Shell获取git信息和编译时间

记录软件版本每一个编译的时间和log信息:

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
GIT_SHA1=`(git show-ref --head --hash=8 2> /dev/null || echo 00000000) | head -n1`
GIT_DIRTY=`git diff --no-ext-diff 2> /dev/null | wc -l`
BUILD_ID=`uname -n`"-"`date +%Y%m%d%H%M%S`
test -f release.h || touch release.h
(cat release.h | grep SHA1 | grep $GIT_SHA1) && \
(cat release.h | grep DIRTY | grep $GIT_DIRTY) && exit 0 # Already up-to-date
echo "#define REDIS_GIT_SHA1 \"$GIT_SHA1\"" > release.h
echo "#define REDIS_GIT_DIRTY \"$GIT_DIRTY\"" >> release.h
echo "#define REDIS_BUILD_ID \"$BUILD_ID\"" >> release.h
#touch release.c # Force recompile of release.c
  • 结果:
    1
    2
    3
    #define REDIS_GIT_SHA1 "ed5b0648"
    #define REDIS_GIT_DIRTY "13"
    #define REDIS_BUILD_ID "xxxx-pc-20180918152335"

release.h

-------------本文结束感谢您的阅读-------------
  • 本文作者: Winddoing
  • 本文链接: https://winddoing.github.io/post/56769.html
  • 作者声明: 本博文为个人笔记, 由于个人能力有限,难免出现错误,欢迎大家批评指正。
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!