git中如何使用标签管理软件版本 [英] How do you use tags in git to manage software versions

查看:14
本文介绍了git中如何使用标签管理软件版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 git 来管理我们的项目,我们每个都有一个分支:开发者分期生产

我想使用 git 标签来管理软件的版本.据我所知,我是否在分支上并添加了一些提交,然后我必须运行:git 标签 1.0

使用我们所达到的任何版本号替换 1.0,然后我可以使用以下方式推送标签:git push origin 1.0

我可以更新分支:git push --tags

但是我现在如何重用标签呢?如果我向本地存储库提交更多代码并希望它轻松成为 1.0 版?还是只是添加一个新标签,比如 1.1?

另外,如果我的同事在他的本地存储库中使用相同的标签名称,并且我们都将相同标签的代码向上推送,会发生什么情况?

最后,如果我们在没有运行 git tag 标记提交的情况下不小心推送了代码会发生什么.

我并没有真正了解标签是如何工作的,我认为它们会像您标记博客文章或其他内容一样工作 - 您可以使用相同的标签标记许多不同的提交并重用标签等.有点像分支我猜.

解决方案

但是我现在如何重用标签呢?如果我向本地存储库提交更多代码并希望它轻松成为 1.0 版?还是只是添加一个新标签,比如 1.1?

你可以用git tag -d 1.0删除标签,然后在服务器上用git push origin :refs/tags/1.0删除.

但最佳实践是仅标记发布,然后在创建标记的位置为该发布创建维护分支.在该分支上,您推送您的修复程序,并在发布更新版本时使用 1.1、1.2、... 进行标记.将代码提供给客户后移动标签是不好的做法.

<块引用>

另外,如果我的同事在他的本地存储库中使用相同的标签名称,并且我们都将相同标签的代码向上推送,会发生什么情况?

我很确定你们中的第二个推送标签会收到错误.自己试试看会发生什么:

git checkout -b testbranchgit标签测试1git push 原始标签 test1git 标记 -d 测试1触摸测试文件git 添加测试文件git commit -m "添加测试文件"git push origin 测试分支git标签测试1git push 原始标签 test1

<块引用>

最后,如果我们在没有运行 git tag 标记提交的情况下不小心推送了代码会发生什么.

您应该在推送提交后推送您的标签.你不能同时做这两个(git push --tags 不推送提交,只推送标签).如果您先推送标签,那么在您推送提交之前,遥控器将具有悬空引用.所以你应该这样做

git push origin mastergit push origin --tags

或类似的,取决于你的情况.

<块引用>

我并没有真正了解标签是如何工作的,我认为它们会像您标记博客文章或其他内容一样工作 - 您可以使用相同的标签标记许多不同的提交并重用标签等.有点像分支我猜.

标签就像提交上的标签,因此您可以将某些提交标记为特殊".最常见的是,这用于标记版本,因此如果客户报告错误,您可以随时返回并查看该版本中的确切内容.

We use git to manage our project, we have a branch for each: dev staging production

I want to use git tags to manage versions of the software. As far as I can see if I am on a branch and add a few commits, I then have to run: git tag 1.0

Repacing 1.0 with whatever version number we are up to, then I can push the tag using: git push origin 1.0

And I can update the branch with: git push --tags

But how do I reuse a tag now? If I commit more code to my local repository and want it to be version 1.0 easily? Or do you just add a new tag like 1.1?

Also, what happens if my colleague uses the same tag name on his local repository and we both push the code for that same tag up?

Lastly, what happens if we accidentally push our code without running git tag to tag the commits.

I'm not really getting how tags work, I thought they would work like you would tag a blog post or something - you can tag lots of different commits with the same tag and reuse the tag etc. kind of like a branch I guess.

解决方案

But how do I reuse a tag now? If I commit more code to my local repository and want it to be version 1.0 easily? Or do you just add a new tag like 1.1?

You can delete the tag with git tag -d 1.0, then delete it on the server with git push origin :refs/tags/1.0.

But the best practice is to only tag releases, and then create a maintenance branch for that release at the point where the tag is created. On that branch you push your fixes, and tag with 1.1, 1.2, ... as you make updated releases. It is bad practice to move a tag after you've given that code to a customer.

Also, what happens if my colleague uses the same tag name on his local repository and we both push the code for that same tag up?

I'm pretty sure the second one of you to push the tag will receive an error. Try it yourself to see what happens:

git checkout -b testbranch
git tag test1
git push origin tag test1
git tag -d test1
touch testfile
git add testfile
git commit -m "Added testfile"
git push origin testbranch
git tag test1
git push origin tag test1

Lastly, what happens if we accidentally push our code without running git tag to tag the commits.

You should push your tags after you've pushed the commits. You cannot do both at the same time (git push --tags does not push commits, only tags). If you push tags first, the remote will have dangling references until you push the commits. So you should be doing

git push origin master
git push origin --tags

or similar, depending on your situation.

I'm not really getting how tags work, I thought they would work like you would tag a blog post or something - you can tag lots of different commits with the same tag and reuse the tag etc. kind of like a branch I guess.

Tags are like labels on commits, so you can mark some commits as being 'special'. Most commonly, this is used to tag releases, so you can always go back and see exactly what was in that release if a customer reports a bug.

这篇关于git中如何使用标签管理软件版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆