代码拉取完成,页面将自动刷新
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"
)
// Basic example of how to checkout a specific commit.
func main() {
CheckArgs("<url>", "<directory>", "<commit>")
url, directory, commit := os.Args[1], os.Args[2], os.Args[3]
// Clone the given repository to the given directory
Info("git clone %s %s", url, directory)
r, err := git.PlainClone(directory, false, &git.CloneOptions{
URL: url,
})
CheckIfError(err)
// ... retrieving the commit being pointed by HEAD
Info("git show-ref --head HEAD")
ref, err := r.Head()
CheckIfError(err)
fmt.Println(ref.Hash())
w, err := r.Worktree()
CheckIfError(err)
// ... checking out to commit
Info("git checkout %s", commit)
err = w.Checkout(&git.CheckoutOptions{
Hash: plumbing.NewHash(commit),
})
CheckIfError(err)
// ... retrieving the commit being pointed by HEAD, it's shows that the
// repository is poiting to the giving commit in detached mode
Info("git show-ref --head HEAD")
ref, err = r.Head()
CheckIfError(err)
fmt.Println(ref.Hash())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。