Thursday 2 April 2020

git tag

Create git tag in old commit

I like to add git tag to one of my old commits, say, e9c4a35.

% git tag                
% git tag -a v1.0 e9c4a35
or 
% git tag -a v1.0 e9c4a35 -m 'multi page complete'

% git tag                
v1.0

Then you push the tag to remote server

% git push origin v1.0
Enumerating objects: 1, done.

Now your github site will have this tag.
See more in
or
visual github

How to create remote git tag without local tag with hash code, I don't know.

<annotated vs non-annotated tag>

When you use git tag <tagname>, Git will create a tag at the current revision but will not prompt you for an annotation. It will be tagged without a message (this is a lightweight tag).

When you use git tag -a <tagname>, Git will prompt you for an annotation unless you have also used the -m flag to provide a message.


https://stackoverflow.com/questions/11514075/what-is-the-difference-between-an-annotated-and-unannotated-tag



<git describe>

The command finds the most recent tag that is reachable from a commit. If the tag points to the commit, then only the tag is shown. Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit.

By default (without --all or --tags) git describe only shows annotated tags

https://git-scm.com/docs/git-describe

<git describe --tags>

It shows any tag found in refs/tags namespace. This option enables matching a lightweight (non-annotated) tag.

If the environment is on a branch that is 14 commits ahead of the last tag, this will show, eg, v0.0.1-14-gXXX, where XXX is SHA hash value.

https://git-scm.com/docs/git-describe
https://www.soliantconsulting.com/blog/versioning-with-git-describe/


<git push with tag>

By default, the git push command doesn’t transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches — you can run git push origin <tagname>.

https://git-scm.com/book/en/v2/Git-Basics-Tagging
https://stackoverflow.com/questions/5195859/how-do-you-push-a-tag-to-a-remote-repository-using-git




<problem with git describe --tags>
 git push -f origin CE-7757

I pushed without tag, but it still prints tag information.


#!/bin/bash -eo pipefail
echo "$(git describe --tags)"
echo 'cur_version=$(git describe --tags)' >> $BASH_ENV
v0.0.1-7-g6e4a85b4f




<CIRCLE_TAG is empty>

https://discuss.circleci.com/t/circle-tag-is-empty/18919?utm_medium=SEM&utm_source=gnb&utm_campaign=SEM-gb-DSA-Eng-ni&utm_content=&utm_term=dynamicSearch-&gclid=EAIaIQobChMI0f2W_OnG6AIVRw4rCh2lhAxYEAAYASAAEgLsOPD_BwE

https://support.circleci.com/hc/en-us/articles/360020342494-The-built-in-environment-variable-CIRCLE-TAG-is-not-present


<git push - NO BRANCH BUT TAG???>


git push without parameter
https://stackoverflow.com/questions/948354/default-behavior-of-git-push-without-a-branch-specified

<example>

$ git commit -a -m 'test v0.0.0'
[CE-7757 334779fbc] test v0.0.0
 1 file changed, 2 insertions(+), 2 deletions(-)
$ git tag v0.0.0
$ git describe --tags
v0.0.0

$ git commit -a -m 'test v0.0.1'
[CE-7757 d077f2b85] test v0.0.1
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git tag v0.0.1
$ git describe --tags
v0.0.1

$ git push origin CE-7757 v0.0.0
Counting objects: 8, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (8/8), 763 bytes | 763.00 KiB/s, done.
Total 8 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 2 local objects.
To github.com:xxx.git
   97635f5ee..d077f2b85  CE-7757 -> CE-7757
 * [new tag]             v0.0.0 -> v0.0.0





After the push, search by branch and tag will give you different point of HEAD.






Also, note the push result. Circleci does not returns v0.0.0 but v0.0.0-1-gxxx because the 'git describe --tags' will return 'the most recent tag reachable from the commit'. Considering entire commits, current commit was 1 time after the tag commit. The server github does not have any idea about v0.0.1 yet, but knows that the last commit (by branch) is 1 time after the tag's commit. So...the same command 'git describe --tags' can show different result when you run it on local machine and remote circle ci environment (if you use different tag on push).



No comments:

Post a Comment