Git Special Topic: The real usage of Git in the development process-tag

Preface

I haven’t used git for project management for a long time, mainly because I forgot how to use it hahaha. . After creating the project and building the git warehouse, there are no other actions. This time I review and apply it and share it with everyone!

text

tag tag (version number)

What is a tag?

        A tag can be thought of as a snapshot or a tag . No matter how you modify the file later, you can specify a rollback to this tag through a command. You can imagine that you take a picture of your childhood, and then you go out and work hard for ten years and find that everything is not going well. Then you can travel through time and space and return to the moment recorded in this picture, which is equivalent to restarting hahaha. Of course this is nonsense, there are no regrets in life. .

How to use it in project development

Create a new label. When creating a new label, the latest commit will be selected by default.

git tag <tag-name> //创建【轻量级】标签

 or

git tag -a <newTag-name> -m "注释" //创建附注标签:-m 后面是附注信息

use

When there are errors that cannot be changed during project rectification in the later stage, you can jump directly to a certain submission you want to jump to and just specify the label:

git checkout <tag-name>

expand

Expansion: What should you pay attention to when checking out tags?

Problem: When you modify and submit the submission status under a certain tag, the modifications may be lost.

Solution:

After executing this command, Git will point HEAD to the label, allowing your code to roll back to the commit state pointed to by the label.

This rollback method is in the form of a detached head pointer (detached HEAD). If modifications are made directly and submitted, the modifications may be lost, so it is recommended to work on a new branch.

If you want to roll back to a tag on a new branch and continue working on that branch, you can use the following two commands:

git checkout -b <newBranch-name> <tag-name>

This will create a new branch named <newBranch-name> and switch it to the commit state pointed to by the specified tag. This way you can work under the new branch without affecting the original branch.

Extension: How to label submitted status?

Question : When you remember yesterday’s submission and forgot to tag it, how to remedy it?

Solution:

First look at the commit history of the current branch and find the commit hash of the commit you want to label:

git log

//或者

git log --oneline

 PS: The git log command will display all commit details, while the git log --oneline command will display simpler commit information.

Then create a label on the specified commit!

git tag <newTag-name> <commmit-hash>

//或者

git tag -a <newTag-name> <commit-hash> -m "附注"

Expansion: A tag was created by mistake and pushed to the remote. How to deal with it?

Question: When you create a tag by mistake and push it to the remote, how should you delete the remote tag and local tag?

Solution :

The first is to make sure the tag exists and get <tag-name>:

git tag

Then delete the specified local tag based on <tag-name>:

git tag -d <tag-name>

 Next is to delete the remote tag. There are two ways:

git push origin :refs/tags/<tag-name>

or

git push origin --delete <tag-name>

First make sure the tag exists on the remote repository

git ls-remote --tags <remote-name>  //remote-name是远程仓库的名称,通常是origin

Then enter the command to delete it. as follows

In this way, the local and remote repositories will no longer have this tag after deletion!

Preview for the next issue: "Git Special Topic: The Real Usage of Git in the Development Process - Branch"

Guess you like

Origin blog.csdn.net/Ccc67ol/article/details/132476457