17

Is it possible to find who deleted a git tag from a repository?

Suppose you have a repository with contributors. The repository has the dev tag and versions: v0.1.0, v0.1.1 etc.

Someone deletes a tag. How would you find who deleted the git tag?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474

3 Answers3

8

You have two types of tags:

  • lightweight
  • annotated

The lightweight tags are only metadata for a commit. They have no author by themselves. Saying that the author of a tag is the author of the commit is wrong, since anyone else could have tagged that commit with a lightweight tag.

The annotated tags are on the other hand like commits. That is why the annotated tags also need a message when you create them. They have an author, description, etc.

So, to know the authors of your tags, you must have an annotated tag policy. But, from what I know there is no history of a git repo metadata (.git directory). This means you cannot know who deleted a tag/branch/etc, unless your git provider has a mechanism to audit/log/this.

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
5

Following this git tip about restoring deleted tags, you can do the following:

Find all unreachable tags in git fsck:

git fsck --unreachable | grep tag

And then, for each commit hash in the output, run

git show COMMIT_HASH

If you want a shell script for listing all unreachable (deleted) tags with the relevant person (Tagger), you could run the following command:

for commit in `git fsck --unreachable | grep tag | awk '{ print $3 }'`; do 
   git show $commit | grep -E "^(tag|Tagger)"; 
done

EDIT: This does not answer the actual question asked, but it tells you how to see the authors of all unreachable tags in the index.

Update 2: These unreachable commits will disappear after a certain expiration period when garbage collection runs.

Juan
  • 1,204
  • 1
  • 11
  • 25
Frost
  • 11,121
  • 3
  • 37
  • 44
  • 3
    This finds all unreachable tag objects, but tag objects are not created for all tags. Also, this shows who created the tag, but the question asks to find who deleted the tag. –  Sep 05 '13 at 11:51
  • Hm... That's interesting. Why wouldn't tag objects be created for all tags? – Frost Sep 05 '13 at 11:53
  • 1
    Tag objects don't get created for a simple `git tag tag-name`, because there is no reason why they would be. If you do that, a ref is added, and that's all that's needed. Tag objects only get created with `git tag -[asu]`, see `git help tag`, when a message is to be stored along with the tag, which does not belong with a commit. –  Sep 05 '13 at 11:56
  • @Frost When I run first command I get this output: `Checking object directories: 100% (256/256), done. Checking objects: 100% (546/546), done.` There is no commit hash... – Ionică Bizău Sep 09 '13 at 06:25
  • @Johnツ Well, if after reading the comments from hvd comments, I see that my answer doesn't actually answer the question asked. – Frost Sep 09 '13 at 07:08
1

Git doesn't really log what happens during the push. This post git: how to see changes due to push?, suggests that the reflog is updated on a push, but I doubt it will log a tag deletion.

You can disable tag deletion on a push (and it's a good idea): Disable tag deletion

Community
  • 1
  • 1
CharlesB
  • 86,532
  • 28
  • 194
  • 218