在Makefile中,如何获取并为变量分配git commit hash?

时间:2016-01-11 01:42:00

标签: git makefile

使所有克隆git repo。我想知道提交哈希是什么,并将git commit hash分配给一个变量,该变量稍后可以在Makefile中使用

e.g。

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)'

2 个答案:

答案 0 :(得分:2)

如何使用shell函数和2个目标呢?

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

答案 1 :(得分:0)

我不确定原因,但似乎git clone $(shell)无法cd进入目录。你可以做的只是在一次$(shell)电话中执行整个行为。

all: download
      echo '$(GIT_COMMIT)'

download:
      $(eval GIT_COMMIT = $(shell git clone git@github.com:proj/project.git buildarea/project && cd buildarea/project && git rev-parse HEAD))
      echo '$(GIT_COMMIT)'