git查看tag

git查看tag命令:

ershixiongdeMacBook-Pro:spring-boot zzs$ git tag
v2.2.0.M1
v2.2.0.M2
v2.2.0.M3
v2.2.0.M4
v2.2.0.M5
v2.2.0.M6
v2.2.0.RC1
v2.2.0.RELEASE
v2.2.1.RELEASE

git切换到tag

git clone整个仓库后,使用以下命令就可以取得对应tag的代码:

git checkout tag_name 

此时git可能会提示你当前处于“detached HEAD” 状态。因为tag相当于一个快照,不能修改它的代码。需要在tag代码基础上做修改,并创建一个分支:

git checkout -b branch_name tag_name

上面命令的意思切换到指定的tag(tag_name),并创建一个分支,本地重新命名(branch_name)。

以SpringBoot的版本为例:

git checkout -b tag-2.2.1.RELEASE v2.2.1.RELEASE

其中tag-2.2.1.RELEASE为本地命名,v2.2.1.RELEASE为github上springboot项目自身的tag命名。

查看分支情况

使用以下命令可查看本地分支情况:

ershixiongd:spring-boot zzs$ git branch
  master
* tag-2.2.1.RELEASE

查看远程的分支情况:

ershixiongdeMacBook-Pro:spring-boot zzs$ git branch -a
  master
* tag-2.2.1.RELEASE
  remotes/origin/1.0.x
  remotes/origin/1.1.x
  remotes/origin/1.2.x
  remotes/origin/1.3.x
  remotes/origin/1.4.x
  remotes/origin/1.5.x
  remotes/origin/2.0.x
  remotes/origin/2.1.x
  remotes/origin/2.2.x
  remotes/origin/HEAD -> origin/master

git切换分支

git切换分支与切换tag命令一样,查看分支命令:

git branch // 查看本地分支
git branch -a // 查看远程分支

切换分支:

git checkout -b branch_name origin-branch

其中,branch_name为本地起的名字,origin-branch为远程分支名称。



git 切换到tag或branch分支插图

关注公众号:程序新视界,一个让你软实力、硬技术同步提升的平台

除非注明,否则均为程序新视界原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.choupangxia.com/2019/11/21/git-tag-branch/