什么是Git中分支的最近标签? [英] What is nearest tag in the past with respect to branching in Git?

查看:108
本文介绍了什么是Git中分支的最近标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标记图形历史不是线性的。人们不只是标记基线( master )。 例如大多数 JS / CSS库从基线执行分支上的发布以保持清晰的差异历史记录。他们提交释放工件(编译/缩小的JS / CSS),以便用户可以轻松抓取工件而无需构建。如果它们在 master 上标记,那么 master 历史将对构建工件产生巨大的全部差异。



实例:

  bash#cd js / jquery 
/ home / user / devel / js / jquery

bash#git remote -v
origin https://github.com/jquery/jquery.git(fetch)

bash#git co master
已经在'master'

bash#git describe --tags
2.1.0-beta1-590-g47ccf3d

bash#git log --graph --decorate --simplify-by-decoration --oneline --all
* 70605c8(origin / master,origin / HEAD)Ajax:只对表单编码请求
* 47ccf3d(HEAD - > master)属性:删除布尔值时不要将属性设置为false
| * 8339185(origin / compat)测试:使iOS设备的正则表达式更加刚性
| | * f9846ae(标记:3.0.0-alpha1)3.0.0-alpha1
| | /
| / |
...
* | 1185427(标记:2.1.0-beta1)标记2.1.0-beta1版本。

来自在现实世界中是无用的,因为:

  git describe --tags 

我在上面的例子中得到了 2.1.0-beta1 ,但最近的努力是 3.0.0-alpha1

我目前使用的最佳方式是通过以下方式手动查看折叠的提交历史记录

  git log --graph --decorate --simplify by by decoration --oneline --all 

$ b

解决方案

在挖掘Git文档后,我设法写入:

  $ git tag \ 
|同时读t;做\
b =`git merge-base HEAD $ t`; \
echo`git log -n 1 $ b --format =%ai` $ t; \
完成| sort
...
2014-04-18 17:17:51 -0400 2.1.1-rc2
2014-04-30 10:43:39 -0400 2.1.1
2014-05-18 20:47:37 +0400 2.1.2
2014-05-18 20:47:37 +0400 2.1.3
2014-05-18 20:47:37 +0400 2.1.4
2015-07-13 15:01:33 -0400 3.0.0-alpha1

当我对Hg充满信心时,我提出了相应的解决方案:

  $ hg convert \ 
$ (git -C jquery / rev-parse --branches --remotes --tags \
| sed's =。* = - rev& =')\
jquery / jquery- hg /

$ cd jquery-hg
$ hg up -r master

$ hg log -r'tag()'--template'{node} {tags} \ n'\
|同时读取r t; do \
hg log -rancestor($ r ,.)--template{date | isodate} {node} $ t \\\
; \
完成| sort

2014-06-16 03:08 +0400 f6f4d6eb708a33f714a2e0003cb7087762407348 2.1.2
2014-06-16 03:08 +0400 f6f4d6eb708a33f714a2e0003cb7087762407348 2.1.3
2014-06-16 03:08 +0400 f6f4d6eb708a33f714a2e0003cb7087762407348 2.1.4
2015-07-13 15:01 -0400 4abe7e961f0e5eb0e75f03030a80a128553f34c1 3.0.0-alpha1

我可以为〜/ .bashrc 添加别名,这段代码在jQuery / Hibernate / Lunix / Spring源代码上花费了将近4秒,但是一些奇怪的填充不要离开我。是否有单线解决方案?



更新我在https://stackoverflow.com/a/34239190/173149 这里是必不可少的部分:

由于Git使用DAG而非线性历史 - 很难定义距离度量,所以我们可以说 - 哦,这个转速离我的 HEAD !最近!

标记和修订之间距离的一些合理的定义:


  • 最短路径的长度 HEAD 转换为 merge base 与标签(不知道用> git HEAD 和标签之间的 merge base
  • (请参阅上面的脚本)
  • 可从HEAD到达,但从标签无法到达的转换次数

  • ul>

    根据转数<<排序标签的脚本/ strong>,可从HEAD到达,但无法从标签到达:

      $ git tag \ 
    |同时读t;做echo`git rev-list --count $ t..HEAD` $ t;完成\
    | sort -n

    如果您的项目历史记录在提交时有奇怪的日期(由于重新编号或其他历史记录重写或有些白痴忘了更换BIOS电池或其他你在历史上做过的魔术)使用该脚本。


    Tag graph history isn't linear. People don't just tag baseline (master).

    For example most valuable JS/CSS libraries perform release on branch from baseline to keep clean diff history. They commit release artifacts (compiled/minified JS/CSS) so users may easy grab artifacts without necessity to build. If they tag on master then master history will have huge all-on-all diffs on build artifacts.

    Real example:

    bash# cd js/jquery
    /home/user/devel/js/jquery
    
    bash# git remote -v
    origin  https://github.com/jquery/jquery.git (fetch)
    
    bash# git co master
    Already on 'master'
    
    bash# git describe --tags
    2.1.0-beta1-590-g47ccf3d
    
    bash# git log --graph  --decorate --simplify-by-decoration --oneline --all
    * 70605c8 (origin/master, origin/HEAD) Ajax: Only form-encode requests with a body
    * 47ccf3d (HEAD -> master) Attributes: do not set properties to false when removing booleans
    | * 8339185 (origin/compat) Tests: Make regexes for iOS devices more rigid
    | | * f9846ae (tag: 3.0.0-alpha1) 3.0.0-alpha1
    | |/  
    |/|   
    ...
    * | 1185427 (tag: 2.1.0-beta1) Tagging the 2.1.0-beta1 release.
    

    Tricks from How to get the latest tag name in current branch in Git? are useless in real world, for:

    git describe --tags
    

    I get 2.1.0-beta1 in above example, but most recent effort is 3.0.0-alpha1.

    The best way I currently have is reviewing collapsed commit history manually from:

    git log --graph --decorate --simplify-by-decoration --oneline --all
    

    解决方案

    After digging to Git docs I managed to write:

    $ git tag \
         | while read t; do \
             b=`git merge-base HEAD $t`; \
             echo `git log -n 1 $b --format=%ai` $t; \
           done | sort
    ...
    2014-04-18 17:17:51 -0400 2.1.1-rc2
    2014-04-30 10:43:39 -0400 2.1.1
    2014-05-18 20:47:37 +0400 2.1.2
    2014-05-18 20:47:37 +0400 2.1.3
    2014-05-18 20:47:37 +0400 2.1.4
    2015-07-13 15:01:33 -0400 3.0.0-alpha1
    

    As I fill confident with Hg I made corresponding solution:

    $ hg convert \
        $(git -C jquery/ rev-parse --branches --remotes --tags \
          | sed 's=.*=--rev &=') \
      jquery/ jquery-hg/
    
    $ cd jquery-hg
    $ hg up -r master
    
    $ hg log -r 'tag()' --template '{node} {tags}\n' \
        | while read r t; do \
            hg log -r "ancestor($r,.)" --template "{date|isodate} {node} $t \n"; \
          done | sort
    
    2014-06-16 03:08 +0400 f6f4d6eb708a33f714a2e0003cb7087762407348 2.1.2 
    2014-06-16 03:08 +0400 f6f4d6eb708a33f714a2e0003cb7087762407348 2.1.3 
    2014-06-16 03:08 +0400 f6f4d6eb708a33f714a2e0003cb7087762407348 2.1.4 
    2015-07-13 15:01 -0400 4abe7e961f0e5eb0e75f03030a80a128553f34c1 3.0.0-alpha1 
    

    I can add alias to ~/.bashrc and this code takes near 4 sec on jQuery/Hibernate/Lunix/Spring sources but some strange filling don't leave me. Are there one-liner solution?

    UPDATE I wrote a long answer in https://stackoverflow.com/a/34239190/173149 Here is essential parts:

    Because Git uses DAG and not linear history - it is hard to define distance metric so we can say - oh that rev is most nearest to my HEAD!

    Some reasonable definition of distance between tag and revision:

    • length of shortest path from HEAD to merge base with tag (don't know who to calculate with git command)
    • date of merge base between HEAD and tag (see above script)
    • number of revs that reachable from HEAD but not reachable from tag (see below script)

    Script that sort tags according to number of revs that reachable from HEAD but not reachable from tag:

    $ git tag \
        | while read t; do echo `git rev-list --count $t..HEAD` $t; done \
        | sort -n
    

    If your project history have strange dates on commits (because of rebases or another history rewriting or some moron forget to replace BIOS battery or other magics that you do on history) use that script.

    这篇关于什么是Git中分支的最近标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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