Switch to another Git tag

前端 未结 2 2026
天命终不由人
天命终不由人 2020-12-22 15:24

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         


        
2条回答
  •  时光说笑
    2020-12-22 16:07

    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.

提交回复
热议问题