使用go-git,是否有任何方法检查是否已提交,但尚未将其推到远程?
例如:
$ echo "Hello" > hello.txt
$ git add -A
$ git commit -am "Add hello"
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean我知道我可以使用go-git来检查w,_ = repo.Worktree()和w.Status(),但这似乎并没有给我我想要的东西,除非我遗漏了什么。
发布于 2019-08-20 19:11:25
我跟着冯克的回答,给出了一个解决方案。
func main() {
dir, err := os.Getwd()
CheckIfError(err)
repo, err := git.PlainOpen(dir)
CheckIfError(err)
revision := "origin/master"
revHash, err := repo.ResolveRevision(plumbing.Revision(revision))
CheckIfError(err)
revCommit, err := repo.CommitObject(*revHash)
CheckIfError(err)
headRef, err := repo.Head()
CheckIfError(err)
// ... retrieving the commit object
headCommit, err := repo.CommitObject(headRef.Hash())
CheckIfError(err)
isAncestor, err := headCommit.IsAncestor(revCommit)
CheckIfError(err)
fmt.Printf("Is the HEAD an IsAncestor of origin/master? : %v\n",isAncestor)
}https://stackoverflow.com/questions/57566661
复制相似问题