首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用libgit2从git存储库中的头获取最后一次提交?

问如何使用libgit2从git存储库中的头获取最后一次提交?
EN

Stack Overflow用户
提问于 2013-03-30 10:43:47
回答 1查看 1.6K关注 0票数 3

由于没有复制粘贴示例来获得与libgit2的最后一次提交,所以我想我应该添加一个。libgit2中的实例充分利用了git_oid_fromstr() .

别忘了libgit2在这个时候(2013年3月)已经完全开发了,所以看看官方文档和源代码吧,因为每天都会添加新特性:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-30 10:43:47

代码语言:javascript
复制
git_commit * getLastCommit ( git_repository * repo )
{
  int rc;
  git_commit * commit = NULL; /* the result */
  git_oid oid_parent_commit;  /* the SHA1 for last commit */

  /* resolve HEAD into a SHA1 */
  rc = git_reference_name_to_id( &oid_parent_commit, repo, "HEAD" );
  if ( rc == 0 )
  {
    /* get the actual commit structure */
    rc = git_commit_lookup( &commit, repo, &oid_parent_commit );
    if ( rc == 0 )
    {
      return commit;
    }
  }
  return NULL;
}

一旦您完成了它,就需要调用git_commit_free()。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15717625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档