zoukankan      html  css  js  c++  java
  • Git4:Git标签

    简介

    Git可以对某一时间点上的版本打上标签。人们在发布某个软件版本(比如 v1.0 等等)的时候,经常这么做。本节我们一起来学习如何列出所有可用的标签,如何新建标签,以及各种不同类型标签之间的差别。

    新建标签

    假如说,我们某个应用经过一段时间的开发,完成了某个功能,现在需要往线上发布。我们可以先将开发代码合并到master,然后对当前的master打一个标签,来标识当前的发布版本。假如说就叫v1.0:

    # 将当前代码完成提交
    yanwei@ubuntu:~/git_test$ git add *
    yanwei@ubuntu:~/git_test$ git commit -m "v1.0最后一次提交"
    [master c169872] v1.0最后一次提交
     2 files changed, 1 insertion(+)
     create mode 100644 new.txt
    yanwei@ubuntu:~/git_test$ git status
    位于分支 master
    无文件要提交,干净的工作区
    
    # 创建一个v1.0的tag
    yanwei@ubuntu:~/git_test$ git tag v1.0
    
    # 查看所有的tag
    yanwei@ubuntu:~/git_test$ git tag
    v1.0
    
    # 还可以通过如下方式查看指定的标签:
    yanwei@ubuntu:~/git_test$ git tag -l "v1.*"
    v1.0
    
    

    在上面的示例中,我们看到有了一个v1.0的tag,可是这个tag没有任何的描述信息,也不知道具体是干嘛的。这个时候,我们可以在打tag的时候, 添加一些详细的信息:

    # -a指定标签为含注释的标签,-m指定注释
    yanwei@ubuntu:~/git_test$ git tag -a v1.1 -m "v1.1版本,啥都没改"
    
    

    查看标签详细信息

    如果要查看一个标签的详细信息,可以使用如下方式:

    yanwei@ubuntu:~/git_test$ git show v1.1
    tag v1.1
    Tagger: yanwei <yanwei@douyu.tv>
    Date:   Mon Jul 16 19:07:24 2018 +0800
    
    v1.1版本,啥都没改
    
    commit c16987225db5f8ff65c7ff858eff4a75992f61dd (HEAD -> master, tag: v1.1, tag: v1.0)
    Author: yanwei <yanwei@douyu.tv>
    Date:   Mon Jul 16 19:01:51 2018 +0800
    
        v1.0最后一次提交
    
    diff --git a/code.txt b/code.txt
    index e064e4c..8f8a0e7 100644
    --- a/code.txt
    +++ b/code.txt
    @@ -5,3 +5,4 @@ this is the forth line
     this is the master branch
     this is dev branch
     this is dev branch new line
    +this line for bug
    diff --git a/new.txt b/new.txt
    new file mode 100644
    index 0000000..e69de29
    
    

    切换标签

    切换标签的操作与切换分支的命令相同:

    git checkout [tagname]
    

    后期添加标签

    在一些应用场景中,我们一个版本发布之后,并没有为其添加标签,后期为了规范化管理,回过头来,想对那些版本添加标签,可以使用如下的操作方式:

    # 使用git log列出一些历史版本信息:
    yanwei@ubuntu:~/git_test$ git log --oneline
    c169872 (HEAD -> master, tag: v1.1, tag: v1.0) v1.0最后一次提交
    d69c612 合并bug分支
    67de5f6 修复bug
    ea9a7d5 merge with no-ff
    b89266d (dev) dev branch another commit
    6c1828d 解决冲突
    2015000 master new commit
    187dee6 dev first commit
    0a96a0f forth commit
    e4fb2aa third commit
    227ecaa second commit
    d66bdc0 first commit
    
    
    #指定为dev first commit这个版本打一个标签:
    git tag -a v1.2 187dee6
    

    将标签推送到远端仓库

    默认情况下,git push 并不会把标签传送到远端服务器上,只有通过显式命令才能分享标签到远端仓库。其命令格式如同推送分支,运行git push origin [tagname] 即可:

    git push origin v1.1
    
  • 相关阅读:
    HTML5 Canvas 颜色填充学习
    PHP中使用函数array_merge()合并数组
    div border-radius
    php中数组可以不写下标
    ab apache Benchmarking中链接的写法 记得加上/
    div border-radius画圆
    Why should i use url.openStream instead of of url.getContent?
    Using Java SecurityManager to grant/deny access to system functions
    In Java, what is the default location for newly created files?
    三种纯CSS实现三角形的方法
  • 原文地址:https://www.cnblogs.com/breezey/p/9320792.html
Copyright © 2011-2022 走看看