5 Star 11 Fork 7

Gitee 极速下载/go-git

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/src-d/go-git
克隆/下载
main.go 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
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())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/go-git.git
git@gitee.com:mirrors/go-git.git
mirrors
go-git
go-git
v4.7.0

搜索帮助