简体   繁体   中英

how to create lightweight tag in libgit2

I want to create lightweight tag (no annotated). I read this

https://ben.straub.cc/2013/06/03/refs-tags-and-branching/

and it seems to me that all I have to do is to create reference. But how to do that? I tried something like this but git_reference_create() returns GIT_EINVALIDSPEC

    git_reference * out;
    tag_name = "refs/tags/v1.0";

    git_revwalk *walker;
    git_revwalk_new(&walker, repo);
    git_revwalk_push_ref(walker, tag_name.c_str());

    git_oid id;
    git_revwalk_next(&id, walker);

    if (git_reference_create(&out, repo, tag_name.c_str(),&id, true,NULL) != 0) cerr << "error creating reference : " << tag_name << endl;

    git_revwalk_free(walker);
    git_reference_free(out);

I got it

    git_reference * out;
    git_oid oid;
    tag_name = "refs/tags/v1.0";

    if (git_reference_name_to_id(&oid, repo, "HEAD")!=0) cerr << "error git_reference_name_to_id()" << endl;
    if (git_reference_create(&out, repo, tag_name.c_str(), &oid, true, NULL)!= 0) cerr << "error creating reference : " << tag_name << endl;

    git_reference_free(out);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM