Thursday, July 29, 2021

git - tag

 Tags (label) - Like a tag on your t-shirt @ the store, its  a reference name applied to particular  commit ID.

Git has option to tag a commit in the repository history so that you can find it easily at the later point in time.

To apply tag to a commit
$ git tag -a <pattern->name of the tag> -m "Commit message" <commitid>

If you apply tag on your local repo, it will only be available to local repo.
is it for yourself or for everyone. If its for everyone, you have to apply from remote repo.

Contents of the tag
$ git show <pattern>

Display list of tags available
$ git tag

Push the tags
$ git push --tags
You need to have permission to push tags.

Delete a tag
$ git tag -d <tag>


Naming conversion
QA_data_epic
Release Version:
R1.2
R1.3
R1.4


Lets do by example

1. Lets first clone the repo
$ git https://github.com/abc/myrepo.git workspace00

2. List all tags available
$ cd workstation; git tag

3. Apply tag
- first find a commit ID and apply
$ git log --oneline -2

$ git tag -a "R1.2" -m "Put comment for release 1.2" <commit_ID>
$ git tag -a "R1.2" -m "Put comment for release 1.2" abc123

Now view the tag
$ git log --oneline -2

now,  you can refer this tag to refer to this commit ID.

$ git show R1.2
shows commit ID and message...

Can you have multiple Tags?
Yes, but need to be different type of tag.

Can you apply one tag on one commit and same on different commit id?
- No

Lets apply a tag
$ git tag -a "R1.3 -m "Comment for release 1.3" abc123

You see one commit id has multiple tags on it. But can not use same tag to apply to different commit ID.

$ git tag -a "R1.3" -m "Put comment for release 1.3" abc123
Fatal: Failed to resolve "abc123" as a valid ref.

We can apply a tag only to one commit at a time.
However one commit id can have multiple tag on it.

if you have permission to push the tag, you can do it.

$ git push --tags

Note: In your org, @private repo, you may not have permission to push it.

$ git tag
$ git tag -d R1.3

$ git log --oneline -2

Repo -> Branch -> Commit_ID


Merge VS Rebase

What is rebase?

- Merge is a process of taking content from one branch and put it into another branch. Merge creates a new commit_ID at the destination branch.

- Rebase is in fact a different type of merge. What it does is, it does not add new commit_ID, but it realign the branch.


Lets say you have branch and some commit ID.
You create a new branch (say test) from one commit ID at master.
and you have some new commit IDs on test branch.

Now, go back to your source branch, and if you do a commit; if you modify something on test branch, and if you try to merge something from test branch to its source branch 'master',  what happens is -
it will take the changes at the source branch 'master' and from the barnch where you trying to mesge.  Both of them put together and it creates new reference which is called 'new commit id' through merge.

Rebase
- On a latest commit ID, it will feel like this branch is created on new commit ID.





No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...