1

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?

Kludge
  • 2,653
  • 4
  • 20
  • 42

1 Answers1

2

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

Source: https://github.com/src-d/go-git/issues/599

mkrieger1
  • 19,194
  • 5
  • 54
  • 65