Reputation: 853
I have a question that, I develop my app in a branch, then when I finished that, I merged that branch into my master. I create a tag from master.
on production environment, I have this my application git repository in my workspace. when I release new version, can I just go into that directory, checkout the tag I created?
ps, I think this way can works, but the following make me confused.
$ git branch
* (no branch)
master
I can not find out which tag I am using on production environment, is there any way to display which tag I am using?
Upvotes: 1
Views: 500
Reputation: 323752
on production environment, I have this my application git repository in my workspace. when I release new version, can I just go into that directory, checkout the tag I created?
Yes and no.
Git assumes that you would want to do new work based on currently checked out version. Tags are immutable (unchangeable), so you cannot do new work on tag. Therefore what happens when you do
$ git checkout <tag>
is that Git checks out state of said tag and creates anonymous branch (called "detached HEAD" in git documentation) for you, starting at <tag>
, and where you can create new work.
That's why you see (no branch)
in git-branch output:
$ git branch
* (no branch)
master
The concept of "detached HEAD" is IMVHO quite well explained (with diagrams) in "Git concepts simplified", section "detached HEAD and all that", where git checkout v1.0
operation is explained in detail.
I can not find out which tag I am using on production environment, is there any way to display which tag I am using?
You can use git-describe if you are using annotated / signed tags (created using git tag -s
or git tag -a
), or git describe --tags
if you are using lightweight tags.
For example you would get
$ git describe
<tag>
if you are directly on tag.
Upvotes: 2
Reputation: 2700
you can use git describe --abbrev=0
to display the most recent tag from current commit.
So if you have e.g
tag v1.00
tag v1.01
tag v1.02
tag v2.00
and you git checkout v1.01
, git describe --abbrev=0
will result in:
v1.01
Upvotes: 1
Reputation: 6854
yes, this is how it is intended to be used. be sure to push/pull tags, as they are not by default.
Upvotes: 0