Tag: libgit2

使用libgit2的“git log -1 fullpath / myfile”

我想用libgit2实现git log -1 fullpath/myfile 。 我是libgit2的新手。 我是在正确的轨道上吗? 这是我到目前为止: git_repository_head(&refToHead, repo); headOID = git_reference_oid(refToHead); git_commit_lookup(&headCommit, repo, headOID); headTreeOID = git_commit_tree_oid(headCommit); git_tree_lookup(&tree, repo, headTreeOID); git_tree_entry_byname(tree, “repopath/myfile”); 不幸的是, git_tree_entry_byname似乎不适用于repo的子目录中的文件。 任何的想法? 谢谢你,拉尔斯

visualstudio.com认为最新的libgit2已经过时了

当从visualstudio.com克隆或获取时,我收到一条边带消息“你正在使用旧版本的Git”。 使用自1月10日起的libgit2 commit f1323d9会发生这种情况。 对此有什么我可以做的,这是我应该担心的吗? 它可以用类似的东西复制 #include #include static int cred_acquire_cb(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) { return git_cred_userpass_plaintext_new(cred, “email@address.com”, “token”); } static int sideband_progress_cb(const char *str, int len, void *payload) { printf(“%s”, str); return 0; } int main() { git_libgit2_init(); git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT; clone_options.fetch_opts.callbacks.credentials = cred_acquire_cb; […]

如何使用libgit2提交git存储库?

因为没有复制粘贴示例来创建提交而不使用libgit2的磁盘上的文件 ,据我所知,我认为我应该添加一个。 不要忘记libgit2目前处于全面开发阶段(2013年3月),因此请查看官方文档和源代码,因为每天都会添加新function: libgit2 API 标题非常好评论 – 这是一个例子 广泛的测试可能是灵感的源泉 有一些官方的例子 , general.c是一个很好的起点 灵感可以在LibGit2Sharp中找到 – 这里有一些测试

如何推(使用libgit2)

如何使用libgit2进行推送? (就像控制台上的git push origin master ) 我想使用C版本。 克隆,打开,添加文件到索引和提交工作就像魅力(见代码 )。 测试裸存储库是本地的。 不幸的是,参考和文档对我没有帮助。 示例是非常罕见的并且大部分已过时( 像这样 , git_push_new()函数似乎已经消失)。 我现在猜几个小时了,我想我尝试了参考和示例中所有有意义的代码片段组合。 编辑:我担心libgit2根本不可能做到这一点。 任何人都可以建议我参考,非常/伪造我的恐惧? 互联网/邮件列表中有一些消息来源( [1] , [2] )表示目前不可能推出libgit2,但很快就可能实现。 然而,这些来源已经过时了。 引用包含一些与推送相关的函数(至少按名称)。 但似乎没有一个像我想要的那样工作:(

用libgit2实现’git pull’?

我有一个相对较短的Gist ,它应该使用libgit2来模拟git pull命令的function。 不幸的是,它并没有完全奏效。 总之,代码片段: 调用git_repository_open()来打开磁盘上的存储库 调用git_remote_load()来获取名为“origin”的远程git_remote * 使用GIT_DIRECTION_FETCH标志调用git_remote_connect() 调用git_remote_download()从远程获取对象 根据git_remote_stats() ,确实正在获取对象。 但工作目录不会更改以反映最新的提交。 我尝试添加: git_checkout_head(repo, NULL); ……但这没有任何区别。 输入: git checkout master …在终端中产生以下输出: 已经’掌握’了 您的分支通过1次提交落后于“origin / master”,并且可以快速转发。 我如何快进?

如何使用libgit2通过ssh推送git存储库

既然已经实现了ssh支持,有人可以告诉我如何编写push()函数吗? 我在推动本地文件系统方面取得了一些成功,但是当我尝试ssh时,我只得到一个段错误。 int cred_acquire_cb(git_cred** cred,const char* url,unsigned int allowed_types, void* payload){ check_error(git_cred_ssh_keyfile_passphrase_new(cred,”./bitbucket.pub”,”./bitbucket”,NULL),”keyfile passphrase”); } int main(int argc, const char *argv[]) { char* repo_path=”./hello/.git”; char* remote_name=”origin”; git_repository* repo; git_remote* remote; git_push* push; bool cred_acquire_called; int error; check_error(git_repository_open(&repo, repo_path),”open repo”); check_error(git_remote_load(&remote,repo,remote_name),”load a remote”); git_remote_set_cred_acquire_cb(remote, (git_cred_acquire_cb)cred_acquire_cb, &cred_acquire_called); check_error(git_remote_connect(remote, GIT_DIRECTION_PUSH),”connect remote”); check_error(git_push_new(&push, remote),”new push object”); check_error(git_push_add_refspec(push,”refs/heads/master:refs/heads/master”),”add push refspec”); check_error(git_push_finish(push),”finish […]

如何检索所有对象ID?

我试图使用libgit2获取git存储库中所有对象ID的列表。 我似乎无法找到任何方法。 libgit2有一个方法来获取所有对象ID(或迭代它们),还是我需要手动读取它们?