git diff 简要_Git标记—简要指南

git diff 简要

Git provides an option to tag (or mark) a specific point in your repo which helps you to identify the tag later and also review the changes at any time in the future.

Git提供了一个选项来标记(或标记)您的存储库中的特定点,这可以帮助您以后识别标记并在将来的任何时候查看更改。

You can see tags as a checkpoint in your repo. They are like branches but you can’t add more changes to it once a tag is created. Simple.

您可以在存储库中看到标签作为检查点。 它们就像分支一样,但是一旦创建了标签,便无法对其添加更多更改。 简单。

Most people use tagging to mark a specific release in the project. So they can review those releases later.

大多数人使用标记来标记项目中的特定版本。 因此他们可以稍后查看这些版本。

And it is also a very good practice to use tagging. It helps people to understand how the project has evolved over a period of time.

使用标记也是一种很好的做法。 它可以帮助人们了解项目在一段时间内的发展情况。

创建标签 (Creating tag)

Before creating tags, I like to mention that there are two types of tags.

在创建标签之前,我想提到一下,标签有两种。

Lightweight tags are just simple tags that are just a pointer to a particular commit hash. Mostly these tags are used for temporary reasons.

轻量级标签只是简单的标签,只是指向特定提交哈希的指针。 通常,这些标签是出于临时原因使用的。

Annotated tags are mostly used and have additional info like tagger name, date, and tagging message. If you are tagging for a permanent pointer, you should use annotated tags.

带注释的标签是最常用的,并且具有附加信息,例如标签名称,日期和标签消息。 如果要标记永久指针,则应使用带注释的标记。

创建轻量级标签 (Creating lightweight tags)

git tag <tag_name> Example: git tag v1.1-1w

In the above command, v1.1–1w is the tag name.

在上面的命令中, v1.1–1w是标签名称。

创建带注释的标签 (Creating annotated tags)

git tag -a <tag_name> Example: git tag -a v1.2

-a is the option used to create an annotated tag.

-a是用于创建带注释标签的选项。

You will be prompted with a tag message

系统将提示您标记消息

Image for post

You can write some relevant message for the release and save the file.

您可以为发布写一些相关的消息并保存文件。

The shorthand of the above command is

上面命令的简写是

git tag -a v1.2 -m "Release V1.2"

The above command will take a tag message option.

上面的命令将带有标签消息选项。

And also remember that Git will take the HEAD commit (latest commit) to create the tag.

还要记住,Git将采用HEAD提交(最新提交)来创建标签。

将标签推入遥控器 (Pushing the tags to the remote)

You have to explicitly push tags to the remote.

您必须将标签明确推入遥控器。

git push origin v1.2 // Will push the mentioned tag. git push origin --tags // Will push all the tags to the origin.

标记旧提交 (Tagging old commits)

You can also create a tag from explicitly mentioning the commit hash. As I said before by default, Git will take the HEAD commit to tag.

您还可以通过显式提及提交哈希值来创建标签。 正如我之前所说的,默认情况下,Git将把HEAD commit标记。

To tag an explicit commit

标记显式提交

git tag -a <tag_name> <commit_hash> Example: git tag -a v1.1 84b2bbd

列出所有标签 (Listing all tags)

The above command will list all tags of the repo.

上面的命令将列出仓库的所有标签。

Image for post

To search through the tags, you can use

要搜索标签,您可以使用

-l will take a search pattern and list the relevant tags. The above command will list all tags in the v1 series. * acts as a wildcard.

-l将采用搜索模式并列出相关标签。 上面的命令将列出v1系列中的所有标签。 *用作通配符。

标签信息 (Tag info)

You can view the tag info using

您可以使用查看标签信息

Image for post

In the above example, we have shown the tag info. You can see the tag name, tagger, date, tag message, and the respective commit.

在上面的示例中,我们显示了标签信息。 您可以看到标签名称,标签,日期,标签消息以及相应的提交。

签出标签 (Checking out a tag)

One of the useful features of tagging is that we can review that pointer in the future. You can check-out a tag similar to a branch.

标记的有用功能之一是我们将来可以查看该指针。 您可以签出类似于分支的标签。

git checkout <tag_name>

But by checking-out, you will be gone to the “Detached HEAD” state. It means that you are not supposed to commit any changes to the tag. Even if you commit any change, it won’t be available in the tag or even in any branch.

但是通过签出,您将进入“已分离头”状态。 这意味着您不应该对标签进行任何更改。 即使您提交了任何更改,它也不会在标记或任何分支中可用。

Checking-out the tag helps you to go that pointer and just review the changes.

签出标签可以帮助您找到该指针,然后仅查看更改。

删除标签 (Deleting a tag)

Tags are very lightweight. They won’t consume much space in the repo. But if you need to clean the tags, then you can delete older tags.

标签非常轻巧。 他们不会在仓库中占用太多空间。 但是,如果您需要清洁标签,则可以删除较旧的标签。

To remove the tag from remote

从远程删除标签

git push origin --delete <tag_name>

重新标记标签 (Retagging tags)

Sometimes, you have created a wrong tag. You have to add some commits or remove some commits from the tag.

有时,您创建了错误的标签。 您必须添加一些提交或从标记中删除一些提交。

As we can’t create tags with similar names (tag name is unique), the no-brainier workaround is to delete the tag and create the new one with the same name.

由于我们无法创建名称相似的标签(标签名称是唯一的),因此,无需费力的解决方法是删除标签并创建具有相同名称的新标签。

Another option is to force create a tag.

另一个选择是强制创建标签。

git tag -a -f <tag_name> <optional_commit_hash> Example: 
git tag -a -f v1.2 // Considering HEAD commit git tag -a -f v1.2 84b2bbd // Considering a particular commit

-f is the option to force create a tag. So the tag that was already created will be replaced with the new commit hash.

-f是强制创建标签的选项。 因此,已经创建的标签将被新的提交哈希替换。

To force push the created tag to remote

强制将创建的标签推到远程

git push origin -f --tags

This will force push the tags to the remote.

这将强制将标签推到遥控器。

Remember to use this with caution. If you are force pushing the tags, then your team members who have the tags in their local will face conflicts when they push.

请记住要谨慎使用。 如果您强行推入标签,则在本地具有标签的团队成员在推入标签时会遇到冲突。

Github中的标签和发行 (Tags and releases in Github)

Tags will be listed in Github too. You can see all your tags, edit, and create new ones.

标签也会在Github中列出。 您可以查看所有标签,进行编辑和创建新标签。

Github also has a feature called Releases. Releases are tied to a tag. Whenever you push a tag, a release is also created. You can also create your own release in Github itself which will create a respective tag too.

Github还具有一个称为Releases的功能。 版本与标签绑定。 每当您按下标签时,也会创建发布。 您还可以在Github本身中创建自己的发行版,这也将创建相应的标签。

Most people will create a new release when new version of the product is released to prod.

当产品的新版本发布到产品中时,大多数人会创建一个新版本。

You can see the releases of Rails repo here

您可以在此处查看Rails回购的版本

Tagging is one of the useful features of Git. It helps you to see how your project has evolved over time.

标记是Git的有用功能之一。 它可以帮助您了解项目随着时间的变化。

Thank you for reading, I hope you learned something new :)

谢谢您的阅读,希望您学到了一些新的东西:)

如果您来得这么多,那么我认为您对Git很有兴趣。 您可以订阅我的时事通讯GitBetter以获得Git的技巧,窍门和高级主题。 (If you have come this much, then I think you are much interested in Git. You can subscribe to my newsletter GitBetter to get tricks, tips, and advanced topics of Git.)

翻译自: https://levelup.gitconnected.com/git-tagging-a-brief-guide-1af080b5bb6f

git diff 简要

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值