如何检查最新版本标签

How to checkout latest release tag

我知道如何使用 Checkout(&git.checkoutOptions)plumbing.ReferenceName("<branchName>")plumbing.Hash("<commit hash>") 检出特定的提交或分支,但我希望能够克隆特定的发行版本。关于如何做到这一点有什么想法吗?

您需要在 CloneOptions 中设置 ReferenceName。

git-go 的克隆 v4.1 示例:

r, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
        URL:      "https://github.com/go-git/go-git",
        ReferenceName: plumbing.ReferenceName("refs/tags/v4.1.0"),
        Progress: os.Stdout,
})