切换到另一个Git标签 [英] Switch to another Git tag

查看:506
本文介绍了切换到另一个Git标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看 rspec软件包的版本版本/标记1.1.4?

  cd〜/ Library / Application \ Support / TextMate / Bundles / 
git clone git://github.com /rspec/rspec-tmbundle.git RSpec.tmbundle
osascript -e'tell appTextMateto reload bundles'


  git clone git 

://github.com/rspec/rspec-tmbundle.git RSpec.tmbundle

然后检出标签你想要这样做:

  git checkout tags / 1.1.4 

这将以'分离HEAD'状态检出标签。在这种状态下,你可以环顾四周,进行实验性修改并提交它们,并且在不影响任何分支的情况下通过执行另一个结帐来丢弃这些提交。。

保留所做的任何更改,将它们移动到新的分支:

  git checkout -b 1.1.4-jspooner 

code>

您可以使用以下方式返回主分支:

  git checkout master 

请注意,正如第一次修订版这个答案,还有另一种签出标签的方式:

  git checkout 1.1.4 

但是正如在评论中提到的,如果你有一个同名的分支,这会导致git警告你refname不明确并检查分支默认情况下:

 警告:refname'test'不明确。 
切换到分支'1.1.4'

如果存储库不会在分支和标签之间共享名称。


How do I check out version version/tag 1.1.4 of the rspec bundle?

cd ~/Library/Application\ Support/TextMate/Bundles/
git clone git://github.com/rspec/rspec-tmbundle.git RSpec.tmbundle
osascript -e 'tell app "TextMate" to reload bundles'

解决方案

Clone the repository as normal:

git clone git://github.com/rspec/rspec-tmbundle.git RSpec.tmbundle

Then checkout the tag you want like so:

git checkout tags/1.1.4

This will checkout out the tag in a 'detached HEAD' state. In this state, "you can look around, make experimental changes and commit them, and [discard those commits] without impacting any branches by performing another checkout".

To retain any changes made, move them to a new branch:

git checkout -b 1.1.4-jspooner

You can get back to the master branch by using:

git checkout master

Note, as was mentioned in the first revision of this answer, there is another way to checkout a tag:

git checkout 1.1.4

But as was mentioned in a comment, if you have a branch by that same name, this will result in git warning you that the refname is ambiguous and checking out the branch by default:

warning: refname 'test' is ambiguous.
Switched to branch '1.1.4'

The shorthand can be safely used if the repository does not share names between branches and tags.

这篇关于切换到另一个Git标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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