Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See who deleted git tag

Tags:

git

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?

like image 744
Ionică Bizău Avatar asked Sep 05 '13 11:09

Ionică Bizău


People also ask

Can you see who created a tag in git?

If it's an annotated tag, then yes. You can git show it just like any other object.

What happens when git tag is deleted?

Delete a local Git tag If you try to delete a Git tag that does not exist, you will simply be notified that the tag does not exist. $ git tag -d v2.0 error: tag 'v2.0' not found. If you want to make sure that tags were correctly deleted, simply list your existing tags using the tag command and the “-l” option.

Can git tags be deleted?

Use Git to delete a Git tag To delete the Git tag from the local repo, run the git tag -d tag-name command where tag-name is the name of the Git tag you want to delete.

What happens to tags on deleted branch?

The tag and commit would still exist if the branch is deleted. A branch is simply a way to track a collection of commits.


3 Answers

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.

like image 145
4 revs, 2 users 76% Avatar answered Sep 18 '22 12:09

4 revs, 2 users 76%


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.

like image 34
Frost Avatar answered Sep 18 '22 12:09

Frost


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

like image 20
CharlesB Avatar answered Sep 21 '22 12:09

CharlesB