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?
If it's an annotated tag, then yes. You can git show it just like any other object.
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.
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.
The tag and commit would still exist if the branch is deleted. A branch is simply a way to track a collection of commits.
You have two types of tags:
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With