1

I am facing issue that I would like to use more tags for specific commit (last one or in history). For example I would like to have commit which contain tags: "v1.2" and "Release" or "XF-update".

First step is to create and push tags:

I can create tag(s):

git tag v1.2
git tag Release
git tag XF-update

I can push them (each separate for safety):

git push remote v1.2
git push remote Release
...

or all together

git push --tags

note: tag Release or XF-update will be push just once and never more, they will be re-use in branch on many places. so I want to say that I want to tag many commits with the same tag. So after month I will create just new tag "v1.4" and not create XF-update tag anymore but still want to use that tag for commits.

Second step is to make a commit about changes:

  • just regular code changes and commit them. note: question is in this case of commit I can already put tags and push it. But to be honest I will prefer to finish commit, push it to remote and in next step start connecting tags to specific commits.

Third step should be to make relation between already created tags and commits in history.

  • by commits in history I mean even last commit, or week old commit (always by hash id)

And here is the problem. I dont know how to say to git that commit with hash "xxxxxxxxxxxxxxxxxxxxxxxxxxx"should be tagged with tags "v1.2" and also with tag "XF-update" (which are already created and pushed). I can imagine to make it even in separate steps:

  • add one specific tag to one specific commit
  • add second specific tag to the same specific commit
  • ....

Any advice? I am using fork and in GUI I am not able to click it by hand, so I need to use git bash which is integrate there. (its not big deal to write few lines, but dont know what should be steps of this specific way)

Thank you!

1
  • 2
    Each tag can only point to one specific commit. You can remove the old tag and make a new tag for the newly chosen commit, or use git tag -f to have Git do the same thing (remove the old tag and make a new tag). But you will only be tagging one commit. Humans generally do not expect tags to "move", so make sure that this is acceptable before you proceed. Commented Apr 14, 2021 at 0:04

2 Answers 2

5

Your question is rather confusing, because you keep jumping back and forth between two different things:

  1. Adding multiple tags to a single commit. This is easy, and you've already done it with your example commands. You can create any number of tags at the currently checked out commit; or at any commit you know the hash for e.g. git tag new_tag abc123def. You can also create a tag pointing at the same commit as another tag by using git tag new_tag existing_tag^{commit} (the ^{commit} at the end makes sure the new tag points directly at the commit, rather than being a pointer to a pointer).
  2. Adding multiple commits to a single tag. This is impossible, because that's just not what a tag is. A tag is a way of finding a specific commit in your history - the most common use is to tag stable releases, so that you can always know "this commit was the one released as v1.2.3". You can use the tag name in most places you'd use the commit hash, because it points specifically at one commit.

It sounds like what you are looking for is some kind of label that you can apply to a set of commits, after those commits have been created. There is apparently a facility called git notes which allows you to add free text notes to existing commits. I don't know anything more about it, but it might be usable for your use case. (Hat tip to jthill for pointing out that it exists.)

Sign up to request clarification or add additional context in comments.

7 Comments

Git notes is the mechanism for adding arbitrary notes to commits later, getting good use out of it requires a bit of project specific policy and discipline that you get to supply
@jthill Ah, I'd never heard of that. If you can summarise how to use it, that's probably the answer the OP's actually looking for.
@NeilG I've rolled back your change, because it made the answer not make sense ("two different things" can't be followed by a list from 1 to 4), and went into a lot of detail. The tip about accidentally nesting annotated tags is useful, so I've tried to include a concise explanation of what you should do, rather than lots of details of why.
Just to focus on the OQ, @IMSoP, I think your answer is well targeted because the commands listed in the question use lightweight tags, so it's reasonable to focus on that (although it would be appropriate to mention that explicitly). We can also see "already created tags" are specifically mentioned. I think this means your answer might need a -f option to move the tag.
It's important to note that tagging a tag is not the same as tagging a commit, and tagging a lightweight tag is not the same as tagging an annotated tag. You can have nested tags. To get started on this see this question: https://stackoverflow.com/questions/53578341/git-tag-another-tag
Yes, as I say, I have amended the Answer to use a command that I believe will do the right thing with annotated tags. It doesn't change the fundamental point, though: the question is already confused about what a tag is, and going into details of concepts like "annotated tags" is best left for a different discussion.
That wasn't intended as a reply to you IMSoP, perhaps I should have responded but I just felt the answer wasn't dealing with complexity that is a necessary part of the question. Competent readers at least benefit from a warning if the answer doesn't help them. IMO dumbing down answers is never a functional response. There's no point in feeling sorry for users who are below entry level because even high capacity users won't be assisted by incomplete or misleading content. I therefore added the warning as a bare minimum contribution.
1

Personally, I see tags as labels for commits

To add tags to a spceific commit, I git checkout that commit and create my tags

git checkout xxxxxxxxxxxxxxxxxxxxxxxxxxx
git tag v1.2
git tag XF-update

If the tag is already used, I delete it before and here is the command I use to delete:

  • local git tag: git tag -d <tag_name>
  • remote git tag: git push --delete origin <tag_name>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.