使用 Git 命令获取项目的版本号和提交哈希值

3 min read
PACKAGE_NAME := totime-server
GO_VERSION   ?= 1.18.1
VERSION := $(shell git describe --tags --abbrev=0)
COMMIT_HASH := $(shell git rev-parse --short HEAD)

all: 
	install build

install:
	go mod tidy

PACKAGE_NAME := totime-server 定义了项目的包名。

GO_VERSION ?= 1.18.1 定义了项目使用的 Go 版本,如果未赋值则默认为 1.18.1.

VERSION := $(shell git describe --tags --abbrev=0)COMMIT_HASH := $(shell git rev-parse --short HEAD) 分别使用 Git 命令获取项目的版本号和提交哈希值。