I'm trying to achieve the result of the following git commands programmatically using go-git:
git fetch
git reset --hard origin/<some_branch>
So there's git.Worktree.Reset()
, which gets git.ResetOptions
, which has a Commit
property which is of type plumbing.Hash
. Unfortunately, I can't figure out how to get the hash for origin/<some_branch>
.
How can I do that?
When using Git from the command line you'd need to use rev-parse
(see How to find the hash of branch in Git?).
It seems to be implemented partially in go-git:
There exists a method (*Repository).ResolveRevision which satisfies part of the behavior of
rev-parse