简体   繁体   English

过去,关于Git分支,最近的标签是什么?

[英]What is nearest tag in the past with respect to branching in Git?

Tag graph history isn't linear. 标记图的历史记录不是线性的。 People don't just tag baseline ( master ). 人们不仅标记基线( master )。

For example most valuable JS/CSS libraries perform release on branch from baseline to keep clean diff history. 例如, 有价值的JS / CSS库从基线开始在分支上执行发布,以保持清晰的差异记录。 They commit release artifacts (compiled/minified JS/CSS) so users may easy grab artifacts without necessity to build. 他们提交发布工件(已编译/精简的JS / CSS),因此用户无需构建就可以轻松获取工件。 If they tag on master then master history will have huge all-on-all diffs on build artifacts. 如果它们标记在master那么master历史将在构建工件上产生巨大的差异。

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? 如何在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 . 在上面的示例中我得到了2.1.0-beta1 ,但是最近的努力是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文档之后,我设法写了:

$ 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. 我可以在~/.bashrc添加别名,并且此代码在jQuery / Hibernate / Lunix / Spring源代码上花费将近4秒钟,但是一些奇怪的填充不会离开我。 Are there one-liner solution? 有单线解决方案吗?

UPDATE I wrote a long answer in https://stackoverflow.com/a/34239190/173149 Here is essential parts: 更新我在https://stackoverflow.com/a/34239190/173149中写了一个很长的答案,这是必不可少的部分:

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 ! 因为Git使用DAG而不是线性历史记录- 很难定义距离度量,所以我们可以说-哦,rev最接近我的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) HEAD到带有标签的合并基 的最短路径的长度 (不知道使用git命令计算的人)
  • date of merge base between HEAD and tag (see above script) HEAD和标签之间的合并基础 日期 (请参见上面的脚本)
  • number of revs that reachable from HEAD but not reachable from tag (see below script) 可从HEAD到达但不能从标签到达的转速 (请参见以下脚本)

Script that sort tags according to number of revs that reachable from HEAD but not reachable from tag: 脚本根据HEAD可以到达但标签无法到达的转速对标签进行排序:

$ 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. 如果您的项目历史记录中的提交日期有奇怪的日期(由于重新设置了基准,或重写了其他历史记录,或者由于白痴而忘记了更换BIOS电池或您对历史记录所做的其他操作),请使用该脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM