【发布时间】:2020-07-13 11:58:56
【问题描述】:
我正在尝试使用 Makefile 中的“git --pretty”格式获取文件的版本(提交哈希的前 7 个字符)。
下面是我的 Makefile
#CUR_LOC_VERSION:= $(shell git log --pretty=format:%H -n1 -- | grep -o '^.\{7\}') # works
CUR_LOC_VERSION:= $(shell git log --pretty=format:%H -n1 -- ../inter/local.py | grep -o '^.\{7\}') # doesn't work, returns empty string
$(info $$CUR_LOC_VERSION is [${CUR_LOC_VERSION}])
我希望它显示提交哈希,但它返回空字符串。
$CUR_LOC_VERSION is []
但上述命令在直接在 shell 中运行时运行良好(而不是通过 Makefile 调用)。
高度赞赏的任何指针。
目录结构。
.
|-- inter
| |-- local.py
|
`-- vhdl
|-- Makefile
【问题讨论】:
-
执行这个 Makefile 时的工作目录是什么?
../inter/local.py是相对于该 wd 时位于您的 git 存储库中的路径吗? -
可能是 '\' 和嵌套替换的问题;一次通过make,一次通过shell。尝试在 grep 模式中添加额外的“\”。
-
你为什么使用
grep?直接输出format:%h,不做任何处理。 -
@LeGEC- 我已经更新了目录结构。路径 ../inter/local.py 位于相对于工作目录的 git repo 中。
-
@Andreas 问题似乎出在 git 部分而不是 grep 部分。