gpt4 book ai didi

go - 如何使用 go-git 查找 sha of origin/master?

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:25 27 4
gpt4 key购买 nike

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

  1. git ls-remote git@github.com:StevenACoffman/toolbox.git
  2. git rev-parse origin/master

有没有其他方法可以使用 go-git 确定 origin/master 的 SHA1?

最佳答案

糟糕!支持 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())
}

关于go - 如何使用 go-git 查找 sha of origin/master?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57577054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com