Search code examples
gittagscommit

How to add multiple already created tags into specific commit? (GIT)


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!


Solution

  • 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 a tag pointing at the same commit as another tag by using git tag new_tag existing_tag, or pointing at a commit you know the hash for e.g. git tag new_tag abc123def
    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.)