get all the lightweight tags created for a specific annotated tag #1940
Unanswered
AlesyaSeliazniova30032012
asked this question in
Q&A
Replies: 2 comments 1 reply
-
The response of ChatGPT seems reasonable, it's reproduced here. import git
# Open the repository
repo = git.Repo('/path/to/your/repo')
def get_lightweight_tags_for_annotated_tag(repo, annotated_tag_name):
# Get the commit associated with the annotated tag
annotated_tag = repo.tags[annotated_tag_name]
if annotated_tag.tag:
annotated_commit = annotated_tag.tag.commit
else:
raise ValueError(f"{annotated_tag_name} is not an annotated tag")
# List all lightweight tags that point to the same commit
lightweight_tags = []
for tag in repo.tags:
if tag.tag is None and tag.commit == annotated_commit:
lightweight_tags.append(tag.name)
return lightweight_tags
# Example usage
annotated_tag_name = 'annotated_tag1'
lw_tags = get_lightweight_tags_for_annotated_tag(repo, annotated_tag_name)
print(f"Lightweight tags for {annotated_tag_name}: {lw_tags}") |
Beta Was this translation helpful? Give feedback.
1 reply
-
Just the thought of the question was as follows: is it possible to create several annotated tags within one commit, and register your own lightweight tags for each one. and so that the annotated tags are linked to the corresponding lightweight tags. But as far as I understand, everything is related to commit, and only through commit can you get all the tags associated with it |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I created 2 annotated tag for one commit and manually added different lightweight tags to these annotated tags.
I want to get all the lightweight tags created for a specific annotated tag. For example : annotated_tag1 - lw_tag1, lw_tag2.
How can this be done using GitPython? Thanks
Beta Was this translation helpful? Give feedback.
All reactions