5

I am a bit confused about git tagging even after reading the documentation.

Say I am making changes to my develop branch.

  1. Should I create a tag before making changes, or should I add my tag after making my changes? Which workflow is better?

  2. Initially I was ask to just use git push --tags, but after running git tag I was shown a list of 5 tags (release-1, ..., release-5 ), when I tried running git tag -v release-5 I was prompted with the following errors, the same applies for other releases. Any ideas?

    error: 575bbe56b0c021c51e2b819763c1ff15cc5d2186: cannot verify a non-tag object of type commit.
    error: could not verify the tag 'release-5'
    
  3. If I have used git push to push tags in the Develop branch, followed by a merge to the Master branch, do I still need to do another round of git push --tags

  4. How are tags different from branches? And which is better?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
dissidia
  • 1,531
  • 3
  • 23
  • 53

2 Answers2

8

Should I create a tag first before I do any changes though I know that I can tag it after the changes. Which workflow is better?

You don't have to, but it can help if you want to go back to an identified point.

You need to be aware of two kinds of tags though (as mentioned in git tag):

  • lightweight tags (reference for the SHA-1 object name of the commit object)
  • annotated tags (independent tag object, including a creation date, the tagger name and e-mail, a tagging message, and an optional GnuPG signature): git tag -a myTag or git tag -m "new myTag" myTag both created annotated tags.
    git tag myTag creates a lightweight tag only.

Annotated tags are meant for release while lightweight tags are meant for private or temporary object labels.

cannot verify a non-tag object of type commit.

You can only verify an annotated tags, since it is an independent object which can support an optional gpg signature (that is the signature you are trying to verify with the -v option).
A lightweight tag is just a shortcut to a commit.

git push --tags in the Develop branch:

That is an operation which will impact your remote upstream repo.
And it will push all tags, not just the ones set in the Develop branch.
To push only the ones that matters, I recommend git push --follow-tags

followed by a merge to the Master branch,

That is a local operation done in your local repo, and has nothing to do with the git push just done before.

do I still need to do another round of git push --tags

Both operations are completely unrelated.

How different are the tags different from branches? And which is better?

As opposed to SVN, tags are very different from branches and complement them: one isn't better than the other.

  • branches are for isolating a development effort (see "When should you branch?").
  • tags are for identifying specific points in history as being important (for instance, for marking releases).

Branches can be renamed or deleted easily.
(Annotated) Tags cannot be modified without affecting the history of the git repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your explanation. Another question just pop into my mind. Prior to the question 2 that I have mentioned, I was wondering could it be a cause where I run `git push --tags` even though in my previous commits etc I did not even create any tags? – dissidia Jul 03 '14 at 08:08
  • @dissidia "a cause"? a cause for what? And you should use `git push --follow-tags`: `git push --tags` only work if you did a `git push` first, as opposed to `git push --follow-tags` which does both in one command: http://stackoverflow.com/a/17219399/6309 – VonC Jul 03 '14 at 08:16
  • my bad. I was trying to say because not 'be a cause'... oops. And can I also presume that git tag will be created automatically as soon as a `git push` command is used, irregardless whether I have create a tag before it? – dissidia Jul 03 '14 at 08:41
  • @dissidia so `git push --tags` before creating any tag won't do anything. – VonC Jul 03 '14 at 08:43
  • pardon my understanding, but do you mean what I have stated before your reply, as I have just edited that comment of mine? – dissidia Jul 03 '14 at 08:47
  • 1
    @dissidia didn't see the edit. Again: `git push` alone doesn't push tags (only commits and branches). `git push --tags` pushes them (only if `git push` has been done before). `git push --follow-tags` does both (pushes commit and tags). No tag is created automatically. – VonC Jul 03 '14 at 08:50
  • Got it that `git push` will not do anything to the tags. So, as long as there are no tag creation, whether `git push --follow-tags` or `git push --tags`, it will not be pushing anything as there are nothing to be push right? – dissidia Jul 03 '14 at 09:10
  • 1
    @dissidia yes, correct. Except `git push --tags` won't push *anything* at all (since it is used to push *only* tags), while `git push --follow-tags` will at least push the commits (and not the tags, if said tags weren't created first). – VonC Jul 03 '14 at 09:11
  • Thank you so much and thanks again for putting up with me and my lack of understanding. Feels great to be rid of the doubt in my mind :) – dissidia Jul 03 '14 at 09:14
0

First of all, nice explaination by VonC. Now moving to your question,regarding the workflow for tagging,

  1. You have to tag your initial version of git repo with lightweight or annotated tag (choice is yours), usually i prefer annotated tags. {P.S: its always better to have initial version of tag. It is not must. }
  2. Then make your changes, commit and push them. And again you can simply use git tag command to create a tag and you have to push it using "git push origin --tags".
  3. Once it is done, your tagging is done with your changes. Now if you can check the diff using "git diff tag1 tag2".

I hope it will help you :)

love
  • 1,000
  • 2
  • 16
  • 35
  • 1
    This answer is incorrect, you can tag local branches, and they don't have to be merge commits. Also, it is not necessary to tag the "initial version of your repo", before making any changes, you can create a tag whenever you feel that it is appropriate to do so. –  Jul 04 '14 at 19:59
  • @cupcake: Agreed with your comments, it is not neccessary to have initial tag, but is's my personal suggestion to tag initial version of base code. – love Jul 05 '14 at 03:12