Skip to content
Kunlin Yu edited this page Nov 10, 2022 · 8 revisions

git-tag

Listing all tags

Git

$ git tag

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    foreach (Tag t in repo.Tags)
    {
        Console.WriteLine(t.FriendlyName);
    }
}

Displaying the tag message, or the commit message if the tag is not annotated

Git

$ git tag -n -l myTag

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Tag t = repo.Tags["your-tag-name"];
    Console.WriteLine(t.IsAnnotated ? t.Annotation.Message : ((Commit) t.Target).MessageShort);
}

Creating tags

Lightweight tag pointing at the current HEAD

Git

$ git tag a-nice-tag-name

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Tag t = repo.ApplyTag("a-nice-tag-name");
}

Lightweight tag pointing at a specific target

Git

$ git tag a-better-tag-name refs/heads/cool-branch
$ git tag the-best-tag-name 5df3e2b3ca5ebe8123927a81d682993ad597a584

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Tag t = repo.ApplyTag("a-better-tag-name", "refs/heads/cool-branch");
    Tag t2 = repo.ApplyTag("the-best-tag-name", "5df3e2b3ca5ebe8123927a81d682993ad597a584");
}

Annotated tag pointing at a specific target

Git

$ git tag -a a-good-tag-name 5df3e2b -m "Create a tag pointing at 5df3e2b"

LibGit2Sharp

using (var repo = new Repository("path/to/your/repo"))
{
    Signature tagger = new Signature("James", "@jugglingnutcase", DateTime.Now);
    repo.ApplyTag("a-good-tag-name", "5df3e2b", tagger, "Create a tag pointing at 5df3e2b");
}

Overwriting an existing tag

To be done

Deleting a tag

To be done