在Makefile中,如何获取git commit哈希并将其分配给变量? [英] In a Makefile, how can I fetch and assign a git commit hash to a variable?
本文介绍了在Makefile中,如何获取git commit哈希并将其分配给变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部制作会克隆git存储库.我想知道什么是提交哈希,并将git commit哈希分配给一个变量,以后可以在Makefile中使用
A make all clones the git repo. I want to know what the commit hash is and assign the git commit hash to a variable which can be used later in the Makefile
例如
all: download
echo '$(GIT_COMMIT)'
download:
cd buildarea && git clone git@github.com:proj/project.git
$(eval GIT_COMMIT = $(shell cd buildarea/project && git log -l --pretty=format:"%H"))
echo '$(GIT_COMMIT)'
推荐答案
如何使用shell函数和2个目标呢?
How about use shell function and 2 targets for it?
all: download getver
getver: VER=$(shell cd buildarea/project && git log -1 --pretty=format:"%H")
getver:
@echo GIT_COMMIT=$(VER)
download:
mkdir -p buildarea && cd buildarea && git@github.com:proj/project.git
这篇关于在Makefile中,如何获取git commit哈希并将其分配给变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文