Ionică Bizău
Ionică Bizău

Reputation: 113425

See who deleted git tag

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?

Upvotes: 18

Views: 6582

Answers (3)

Frost
Frost

Reputation: 11977

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.

Upvotes: 5

CharlesB
CharlesB

Reputation: 90396

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

Upvotes: 1

Gabriel Petrovay
Gabriel Petrovay

Reputation: 21914

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.

Upvotes: 8

Related Questions