diff --git a/Software/Development/Environment/Make/Makefile_简明语法.md b/Software/Development/Environment/Make/Makefile_简明语法.md index 8b7ff2f..e8dcfd9 100644 --- a/Software/Development/Environment/Make/Makefile_简明语法.md +++ b/Software/Development/Environment/Make/Makefile_简明语法.md @@ -70,3 +70,9 @@ GIT_BRANCH=$(shell git branch | sed -n '/\* /s///p') ```Makefile GIT_COMMIT=$(shell git log --pretty=format:'%H' -1) ``` + +### 获取最后一个 tag + +```Makefile +GIT_LAST_TAG=$(shell git describe --tags `git rev-list --tags --max-count=1`) +``` diff --git a/Software/Development/Language/Go/Basic/编译_Go_程序时自动添加_GitBranch_和_GitCommit.md b/Software/Development/Language/Go/Basic/编译_Go_程序时自动添加_GitBranch_和_GitCommit.md index ca1d2ce..f4a11d5 100644 --- a/Software/Development/Language/Go/Basic/编译_Go_程序时自动添加_GitBranch_和_GitCommit.md +++ b/Software/Development/Language/Go/Basic/编译_Go_程序时自动添加_GitBranch_和_GitCommit.md @@ -8,6 +8,7 @@ package main var ( GitBranch string GitCommit string + GitLastTag string ) func main() { @@ -15,7 +16,7 @@ func main() { } ``` -通过 go build -ldflags "-X importpath.name=value’ " 赋值字符串 value 给指定包 importpath 中的变量 name。 +通过 go build -ldflags "-X 'importpath.name=value'" 赋值字符串 value 给指定包 importpath 中的变量 name。 -ldflags 会将后边的的参数传递给 go tool link 连接器。 @@ -26,9 +27,10 @@ go tool link 的 -X 会将字符串赋值给指定包中的变量,格式是: ```makefile GIT_BRANCH=$(shell git branch | sed -n '/\* /s///p') GIT_COMMIT=$(shell git log --pretty=format:'%H' -1) +GIT_LAST_TAG=$(shell git describe --tags `git rev-list --tags --max-count=1`) target: - go build -ldflags "-s -X 'main.GitBranch=$(GIT_BRANCH)' -X 'main.GitCommit=$(GIT_COMMIT)'" + go build -ldflags "-s -X 'main.GitBranch=$(GIT_BRANCH)' -X 'main.GitCommit=$(GIT_COMMIT)' -X main.GitLastTag=$(GIT_LAST_TAG)" ``` --pretty=format 可支持: