由于没有复制粘贴示例来获得与libgit2的最后一次提交,所以我想我应该添加一个。libgit2中的实例充分利用了git_oid_fromstr() .
别忘了libgit2在这个时候(2013年3月)已经完全开发了,所以看看官方文档和源代码吧,因为每天都会添加新特性:
发布于 2013-03-30 10:43:47
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()。
https://stackoverflow.com/questions/15717625
复制相似问题