[Git] Mark commit with Tag

♠ Posted by NN TRUNG at 18:14
While you commit your edits, then everything will be all up in her log that showed you how to viewcommit log in the previous section . But if you commit too much, it will cause problems for you later if you need to review information before you commit can tag marker (tag) for each commit and when to see you simply use the command git show tên_tag was made ​​very clear information, in addition it also helps you to easily diff (compare) later when without memory checksum (though just remember the first few letters) of each commit but just remember tag, and can add the tag to your branch from the convenience of the branch.

Lightweight Tag and Annotated Tag

In Git there are two main types of tag are:
  • Lightweight Tag: The tag is merely a snapshot of the commit mark.
  • Annotated Tag: With this tag, you can put the tag titles, and while watching it would have information about the tag, date tag, ....

How to create Lightweight Tag

First, you can type git tag to see a list of tags in your project. Then to create a tag, you can typegit tag tên_tag to create. Eg v1.0 example.
  $ Git tag v1.0
 $ Git tag
 v1.0 
Now you can view the information of tagged commit by running git show tên_tag . Note that it will mark the command on your last commit to the tag v1.0 .
  $ Git show v1.0
 commit 05193375f7a7c1295fd26c6388d81e188f405b0b
 Author: Thach Pham <contact@thachpham.com>
 Date: Thu Apr 23 02:20:50 2015 -0700

  Added a new tag

 diff --git a / tag.html b / tag.html
 100644 new mode file
 Index 0000000..e69de29 

How to create Annotated Tag

To create Annotated Tag, you also use git tag but will have more parameters -a and parameter -m to set the message for this tag.
  $ Git tag -a v1.0-an -m "Launches Version 1.0"
 $ Git show v1.0-Security
 tag-Security v1.0
 Tagger: Thach Pham <contact@thachpham.com>
 Date: Thu Apr 23 02:41:11 2015 -0700

 Launches Version 1.0

 commit d5a599e3385a8fc7a65958ed50bc8b54666b45ad
 Author: Thach Pham <contact@thachpham.com>
 Date: Thu Apr 23 02:40:31 2015 -0700

  Commit for Annotated Tag

 diff --git a / tag.html b / tag.html
 e69de29..fea03c1 index 100644
 --- A / tag.html
 +++ B / tag.html
 @@@@-0.0 +1
 + Annotated Tag 
You can see when you show up, the Annotated tag will have much more information than the tag is normal, and this is also the type of tag you should use to get more information.

Add tag for the old commit

In command on the tag you just created for your last commit. And if you have a lot of previous commit that need tagging, just add the code checksum (or a code checksum) of that commit.
To view the checksum of the previous commit, you can use git log parameter --pretty worth oneline to filter log offline.
  $ Git log --pretty = oneline
 Commit for Annotated d5a599e3385a8fc7a65958ed50bc8b54666b45ad Tag
 Added a new tag 05193375f7a7c1295fd26c6388d81e188f405b0b
 Added 435f642f951fbab1037fc2feef239ab26d6e6115 faq.html
 Initial commit 6904d5232bf90821068279311e205e3e1ff929f1 
And now you can put the tag to commit Initial commit will declare its checksum code in commandgit tag as follows.
  $ Git tag -a v0.0 6904d -m "Tag for inintial commit"
 $ Git tag
 v0.0
 v1.0
 v1.0-Security 

Push Tag

Default command git push will not push the tag made ​​up repository that you can use thegit push --tags to push the tag onto the entire repository.
  $ Git push --tags
 Username for 'https://github.com': thachphamblog
 Password for 'https: //thachphamblog@github.com': 
 Counting objects: 7, done.
 Delta compression using up to 4 threads.
 Compressing objects: 100% (6/6), done.
 Writing objects: 100% (7/7), 775 bytes | 0 bytes / s, done.
 Total 7 (delta 1), reused 0 (delta 0)
 To https://github.com/thachphamblog/hoc-git.git
  * [New tag] v0.0 -> v0.0
  * [New tag] v1.0 -> v1.0
  * [New tag] v1.0-Security -> v1.0-Security 
If you use Github or similar services are now you will see the tag appears in the repository.
git-tag-github

Enter tags to branch

Although in later post I will explain through temporary branch but now you can understand the branch is a fork in a tree project for you edit the source code without affecting the original branch (master).
Now you can access the data you commit through the tag attached to creating a new branch with the command git checkout -b tên_branch tên_tag . For example you want put the tag v1.0-an on a new branch name version1 will write as follows:
  $ Git checkout -b-Security v1.0 version1
 Switched to a new branch 'version1' 
Now that you have automatically transferred via branch version1 rather than master the original, together with data that commits tagged v1.0-an .
Now if you want to work more with this branch is just like when you work in master . To switch back to the master, you type the command git checkout master .
To push this branch up so you can use the command git push origin version1 . If you forget, I repeat then, origin is the name of the remote address that Git repository default character set when you clone.
git-push-branch
Now you try to see what the master version1 and have seen different view of him? In his speech on the branch will explain to you in more detail. The categories that you create a different division to modify its own code without affecting the main code.

Epilogue

In this article, do you see the power of Git is how and when it combines with the branch it will be great in the distribution of the source code to your branch for more flexible working, easily switch between version without doing much. Do not worry if not understand the branch, I will explain shortly in the following section.

0 nhận xét:

Đăng nhận xét