Pages

Monday, March 4, 2019

Git - Understanding Tags

We already understood that branches are separate line of development. When ever we create a branch, we basically take a dump of the master branch code and then make the changes or work on changing the code in that branch. This way we will work on the branch code and will not touch anything in the master branch. Once we are sure that our branch code can be pushed to the master branch we can then do a merge of the 2 branches and once done , we have the updated code in our master.

Let’s say while developing code we want to release the code to the production machine for our testing. So we will take the branch code that is developed and test it. At this moment we will tag the branch code with a version or name and then release that to a machine and then test it.

A tag represents a version of a particular branch at a moment in time. When we create a branch and committed some code to that branch, we can then create a tag using “git tag sample-tag”
jagadishsample$Tue Feb 19@ git tag sample-tag

It is common pattern to use version numbers like v1.4 etc along with a tag. Git supports 2 types of tags, annotated and lightweight.

In the above example we created a lightweight tag. The two types of tags differ with the amount of metadata they store with them. With the annotated tags we store some more meta data like tagger name,email etc. with light weight we only store the name and pointer to the commit. As a best practice annotated tags are for public release since they contain much data and light weight are for private.

Create a annotated tag using,

jagadishsample$Tue Feb 19@ git tag -a simple-tag

This will open the default editor configured and will allow to enter data.
Lightweight tags are created with no options passed as,
jagadishsample$Tue Feb 19@ git tag sample-tag

Listing tags - to list the existing tags use,
jagadishsample$Tue Feb 19@ git tag
sample-tag
simple-tag

Merge to master - Once that we have created the tag for a branch with specific code, we need to push that to the master branch as below using,
jagadishsample$Tue Feb 19@ git merge master sample-tag
Updating ea4ccb9..094b4ac
Fast-forward
tag-example-file | 1 +
1 file changed, 1 insertion(+)
create mode 100644 tag-example-file

Deleting tags - deleting a tag is similar to the branch. Pass a “-D” with the tag and it will delete
jagadishsample$Tue Feb 19@ git tag -d sample-tag
Deleted tag 'sample-tag' (was 094b4ac)

No comments :

Post a Comment