`git tag`按指定日期的时间顺序排序 [英] `git tag` sorted in chronological order of the date of the commit pointed to

查看:854
本文介绍了`git tag`按指定日期的时间顺序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 git tag 的输出按字母顺序排列。我希望它按时间顺序排列(他们被分配的提交日期,而不是他们被创建的日期),否则输出应该保持不变。

我尝试了 http ://networkadmin20.blogspot.de/2010/08/howto-list-git-tags-by-date.html ,但订单仍然相同。



为了确保它与我的存储库不存在错误,我使用一个干净的存储库尝试了以下操作:

  soeren @ubuntu〜/ Projects / sandbox%mkdir chronogit 
soeren @ ubuntu〜/ Projects / sandbox%cd chronogit
soeren @ ubuntu〜/ Projects / sandbox / chronogit%git init
初始化的空Git仓库in /home/soeren/Projects/sandbox/chronogit/.git/
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%touch a
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git添加
s oeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git commit -m'a'
[master(root-commit)f88e0e9] a
0文件已更改
创建模式100644 a
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git tag'A-first'
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git mv ab
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git commit -m'c'
[master ecc0c08] c
1个文件改变,0个插入(+),0个删除( - )
重命名a => b(100%)
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git tag'C-second'
soeren @ ubuntu〜/ Projects / sandbox / chronogit ) - [master]%git mv bc
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git commit -m'b'
[master e72682d] b
1文件已更改,0插入(+),0删除( - )
重命名b => c(100%)
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git tag'B-third'
soeren @ ubuntu〜/ Projects / sandbox / chronogit ) - [master]%git tag
A-first
B-third
C-second
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master] %git for-each-ref refs / tags --sort = taggerdate --format =%(refname:short)
A-first
B-third
C-second

期望的输出是:

  A-first 
C-second
B-third



<

  B-third 
C-second
A-first

编辑:正如评论中指出的那样, 这个问题很相似,所以我尝试了以下内容:

  soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) -  [master]% git log --tags --simplify-by-decoration --pretty =format:%ai%d
2013-09-06 16:08:43 +0200(HEAD,B-third,master)
2013-09-06 16:08:21 +0200(C-second)
2013-09-06 16:07:42 +0200(A-first)



订单没问题,但现在我正在格式化...



<$ p (git) - [master]%git log --tags --simplify-by-decoration --pretty =format:%(refname:简称)
%(refname:short)
%(refname:short)
%(refname:short)
soeren @ ubuntu〜/ Projects / sandbox / chronogit(git) - [master]%git log --tags --simplify-by-decoration --format =%(refname:short)
%(refname:short)
%(refname:short)
%(refname:short)


解决方案

git tag | xargs -I @ git log --format = format:%ai @%n-1 @ |排序| awk'{print $ 4}'


The output from git tag is ordered alphabetically. I would like it to be ordered chronological (the date of the commits they are assigned to, not the date on which they were created), otherwise the output should stay the same.

I’ve tried the suggestion from http://networkadmin20.blogspot.de/2010/08/howto-list-git-tags-by-date.html, but the order is still the same.

To make sure it is not an error with my repository, I tried the following with a clean repository:

soeren@ubuntu ~/Projects/sandbox % mkdir chronogit
soeren@ubuntu ~/Projects/sandbox % cd chronogit 
soeren@ubuntu ~/Projects/sandbox/chronogit % git init
Initialized empty Git repository in /home/soeren/Projects/sandbox/chronogit/.git/
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % touch a
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git add a
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git commit -m 'a'
[master (root-commit) f88e0e9] a
 0 files changed
 create mode 100644 a
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag 'A-first'
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git mv a b
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git commit -m 'c'
[master ecc0c08] c
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename a => b (100%)
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag 'C-second'
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git mv b c
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git commit -m 'b'
[master e72682d] b
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename b => c (100%)
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag 'B-third'
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git tag
A-first
B-third
C-second
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git for-each-ref refs/tags --sort=taggerdate --format="%(refname:short)"
A-first
B-third
C-second

The desired output is:

A-first
C-second
B-third

or, since inverting it shouldn’t be too hard:

B-third
C-second
A-first

Edit: As pointed out in the comments, this question is pretty similiar, so I tried the following:

soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git log --tags --simplify-by-decoration --pretty="format:%ai %d"          
2013-09-06 16:08:43 +0200  (HEAD, B-third, master)
2013-09-06 16:08:21 +0200  (C-second)
2013-09-06 16:07:42 +0200  (A-first)

The order is fine, but now I’m fighting with the formatting…

soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git log --tags --simplify-by-decoration --pretty="format:%(refname:short)"
%(refname:short)
%(refname:short)
%(refname:short)
soeren@ubuntu ~/Projects/sandbox/chronogit (git)-[master] % git log --tags --simplify-by-decoration --format="%(refname:short)" 
%(refname:short)
%(refname:short)
%(refname:short)

解决方案

git tag | xargs -I@ git log --format=format:"%ai @%n" -1 @ | sort | awk '{print $4}'

这篇关于`git tag`按指定日期的时间顺序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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