如何将 HEAD 签出到 libgit2 中的指定引用或标签
how to checkout HEAD to specified reference or tag in libgit2?
我想将我的程序降级到以前的版本。是否可以在libgit2中做到这一点?
有我的代码
string path = "C://Local//Path//to//my//repo";
string tag = "refs/tags/v0.0.4";
git_libgit2_init();
const char * REPO_PATH = path.c_str();
git_repository * repo = nullptr;
git_repository_open(&repo, REPO_PATH);
git_reference *ref;
git_reference_lookup(&ref, repo, "refs/heads/master");
git_reference *new_ref;
git_reference_symbolic_set_target(&new_ref, ref,tag.c_str(),"message");
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
// how to specify options to use ref or tag?
git_checkout_head(repo, &opts);
git_repository_free(repo);
git_libgit2_shutdown();
认为我明白了
git_libgit2_init();
const char * REPO_PATH = path.c_str();
git_repository * repo = nullptr;
git_repository_open(&repo, REPO_PATH);
git_reference *ref;
git_reference_lookup(&ref, repo, "refs/heads/master"); // "refs/remotes/origin/HEAD"
git_reference *new_ref;
git_reference_lookup(&new_ref, repo, tag.c_str());
git_revwalk *walker;
git_revwalk_new(&walker, repo);
git_revwalk_push_ref(walker, tag.c_str());
git_oid id;
git_revwalk_next(&id, walker);
git_reference_set_target(&new_ref, ref, &id, "message");
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
if (0!=git_repository_set_head_detached(repo,&id)) cerr<<"problem occured while detaching head"<< endl;
if (0 != git_checkout_head(repo, &opts)) cerr << "problem checkout head" << endl;
git_revwalk_free(walker);
git_repository_free(repo);
git_libgit2_shutdown();
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 具有默认值的引用获取函数
- 如何使用基类指针引用派生类成员
- 如何将 HEAD 签出到 libgit2 中的指定引用或标签
- 除了自我引用,在typedef中使用标签还有其他原因吗?