在完成origin/master
的等效操作后,我尝试使用go-git查找git fetch --all
的SHA1。但是,go-git似乎也不支持:
git ls-remote git@github.com:StevenACoffman/toolbox.git
git rev-parse origin/master
是否有使用go-git确定origin/master
的SHA1的替代方法?
答案 0 :(得分:0)
哇!支持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())
}