使用 git 标记和分支有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4017508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:20:55  来源:igfitidea点击:

what is the difference between tag and branch with git?

gittagsbranch

提问by egervari

Possible Duplicate:
What is the difference between a tag and a branch in git?

可能的重复:
git 中的标签和分支有什么区别?

What I'd like to do is create checkpoints for different versions of my code. So once I make a bunch of commits, I want to say, "Okay, at this point in the code, this is version 0.1 completed". And then I can make a bunch more commits and do it again and say, "Okay, this point is 0.2 completed".

我想做的是为不同版本的代码创建检查点。所以一旦我做了一堆提交,我想说,“好的,在代码的这一点上,这是 0.1 版完成”。然后我可以做更多的提交,然后再做一次,然后说,“好吧,这点是 0.2 完成了”。

I know how to make a branch and a tag... I just don't understand the difference, and which one will do what I want ;)

我知道如何制作一个分支和一个标签......我只是不明白其中的区别,哪个会做我想做的事情;)

Thanks

谢谢

回答by Jimmy Cuadra

Both branches and tags are essentially pointers to commits. The big difference is that the commit a branch points to changes as you add new commits, and a tag is frozen to a particular commit to mark a point in time as having a certain significance. From one of my favorite Git resources, Pro Git:

分支和标签本质上都是指向提交的指针。最大的区别在于,当您添加新提交时,提交分支指向更改,并且标记被冻结到特定提交以将时间点标记为具有一定意义。来自我最喜欢的 Git 资源之一Pro Git

Like most VCSs, Git has the ability to tag specific points in history as being important. Generally, people use this functionality to mark release points (v1.0, and so on). In this section, you'll learn how to list the available tags, how to create new tags, and what the different types of tags are.

与大多数 VCS 一样,Git 能够将历史中的特定点标记为重要。通常,人们使用此功能来标记发布点(v1.0 等)。在本节中,您将学习如何列出可用标签、如何创建新标签以及不同类型的标签是什么。

A branch in Git is simply a lightweight movable pointer to one of these commits.

回答by Roberto Aloi

A tag represents a version of a particular branch at a moment in time. A branch represents a separate thread of development that may run concurrently with other development efforts on the same code base.

标签代表某一时刻特定分支的版本。一个分支代表一个单独的开发线程,它可以与同一代码库上的其他开发工作同时运行。

SOURCE: This duplicate question.

来源:这个重复的问题

What you want is probably a TAG.

你想要的可能是一个TAG

回答by Vladimir Georgiev

Let's say you have - Super Awesome Product v1.0 that is stable and commited in a git repository.

假设您拥有 - Super Awesome Product v1.0,它在 git 存储库中稳定并提交。

You make bug fixes and changes in the branch that is v1.0 and you tag them with stuff like:

您在 v1.0 的分支中进行错误修复和更改,并使用以下内容标记它们:

  • this fixes work item 1341 - bug ...

  • this version fixes item 234324 - bug ...

  • final v1.0

  • 这修复了工作项 1341 - 错误...

  • 此版本修复了项目 234324 - 错误...

  • 最终版 v1.0

The above are all tags that represent the state of the code ( a LABEL ) when the commit was made. So, when you make v1.5 and a bug comes in for v 1.0, you take the tag final v1.0 and test the bug on it.

以上都是表示提交时代码状态(一个 LABEL )的所有标签。因此,当您制作 v1.5 并且 v 1.0 出现错误时,您将标记最终 v1.0 并在其上测试错误。

NOW! You decide to change the underlying Data Access of Super Awesome product. What do you do? You branch v1.0 and make a new branch called Super Awesome Product NEW DAL branch.

现在!您决定更改 Super Awesome 产品的底层数据访问。你做什么工作?您分支 v1.0 并创建一个名为 Super Awesome Product NEW DAL 分支的新分支。

Tags are for snapshots of daily to daily commits. Branches are for more grand scale changes.

标签用于每日到每日提交的快照。分支用于更大规模的更改。

回答by wilhelmtell

Tags are a fundamental building block in git; branches aren't. Git performs checks to make sure tags remain constant, never change, once created pointing at a commit. A branch on the other hand is a mere reference or pointer to a commit, and it can be updated to point at a different commit freely.

标签是 git 中的基本构建块;分支不是。Git 执行检查以确保标记保持不变,一旦创建指向提交,就永远不会改变。另一方面,分支只是一个提交的引用或指针,它可以自由更新以指向不同的提交。