【问题标题】:go-git: Is it possible to perform a hard reset to origin branch?go-git:是否可以对原始分支执行硬重置?
【发布时间】:2020-02-03 10:18:17
【问题描述】:

我正在尝试使用 go-git 以编程方式实现以下 git 命令的结果:

git fetch
git reset --hard origin/<some_branch>

所以有git.Worktree.Reset(),它得到git.ResetOptions,它有一个Commit 属性,它的类型是plumbing.Hash。不幸的是,我不知道如何获取 origin/&lt;some_branch&gt; 的哈希值。

我该怎么做?

【问题讨论】:

    标签: git go go-git


    【解决方案1】:

    从命令行使用 Git 时,您需要使用 rev-parse(请参阅 How to find the hash of branch in Git?)。

    似乎在go-git中部分实现了:

    有一个方法(*Repository).ResolveRevision满足 rev-parse的部分行为

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

    【讨论】:

      猜你喜欢
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 2012-03-07
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多