我正在尝试使用go-git来查找SHA1 of origin/master,而我已经完成了与git fetch --all相当的操作。然而,go-git似乎也不支持:
git ls-remote git@github.com:StevenACoffman/toolbox.gitgit rev-parse origin/master是否有其他方法可以使用git来确定SHA1 of origin/master?
发布于 2019-08-20 15:38:58
哇!git rev-parse是支持的!使用./main.go $PWD origin/master执行以下操作
///usr/bin/env go run "$0" "$@" ; exit "$?"
package main
import (
"fmt"
"os"
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
"gopkg.in/src-d/go-git.v4/plumbing"
)
// Example how to resolve a revision into its commit counterpart
func main() {
CheckArgs("<path>", "<revision>")
path := os.Args[1]
revision := os.Args[2]
// We instantiate a new repository targeting the given path (the .git folder)
r, err := git.PlainOpen(path)
CheckIfError(err)
// Resolve revision into a sha1 commit, only some revisions are resolved
// look at the doc to get more details
Info("git rev-parse %s", revision)
h, err := r.ResolveRevision(plumbing.Revision(revision))
CheckIfError(err)
fmt.Println(h.String())
}https://stackoverflow.com/questions/57577054
复制相似问题