如何使用go-git找到origin/master的sha?

origin/master在我已经完成了 的等效操作之后,我正在尝试使用 go-git 来查找 的 SHA1 git fetch --all。然而,go-git 似乎不支持:

  1. git ls-remote git@github.com:StevenACoffman/toolbox.git

  2. git rev-parse origin/master

是否有其他方法来确定使用 go-git 的 SHA1 origin/master


互换的青春
浏览 113回答 1
1回答

陪伴而非守候

哎呀!git rev-parse支持!使用以下命令执行./main.go $PWD origin/master:///usr/bin/env go run "$0" "$@" ; exit "$?"package mainimport (&nbsp; &nbsp; "fmt"&nbsp; &nbsp; "os"&nbsp; &nbsp; "gopkg.in/src-d/go-git.v4"&nbsp; &nbsp; . "gopkg.in/src-d/go-git.v4/_examples"&nbsp; &nbsp; "gopkg.in/src-d/go-git.v4/plumbing")// Example how to resolve a revision into its commit counterpartfunc main() {&nbsp; &nbsp; CheckArgs("<path>", "<revision>")&nbsp; &nbsp; path := os.Args[1]&nbsp; &nbsp; revision := os.Args[2]&nbsp; &nbsp; // We instantiate a new repository targeting the given path (the .git&nbsp; &nbsp; &nbsp;folder)&nbsp; &nbsp; r, err := git.PlainOpen(path)&nbsp; &nbsp; CheckIfError(err)&nbsp; &nbsp; // Resolve revision into a sha1 commit, only some revisions are resolved&nbsp; &nbsp; // look at the doc to get more details&nbsp; &nbsp; Info("git rev-parse %s", revision)&nbsp; &nbsp; h, err := r.ResolveRevision(plumbing.Revision(revision))&nbsp; &nbsp; CheckIfError(err)&nbsp; &nbsp; fmt.Println(h.String())}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go