一个`git log`标记如何仅提交? [英] How does one `git log` tagged commits only?
问题描述
我希望 git log
master分支上的所有标记提交(并且没有未标记的提交)。这是可能的吗?
这个秘密技巧是要实现
git log
使用与 git rev-list
相同的规则。后者命令有一个 - tags
标志来查看标签。因此,与目前为止的其他答案一样,如果您愿意查看所有标记的提交,则此单一命令将执行此操作:git log --no-walk --tags
( - no-walk
可以防止它从标签开始,找到所有的父提交以及父母的父母,等等。)
但是你要求在主分支上标记提交,我假定它的意思是(以技术术语来说)通过标记和指向的提交 master
分支。这非常困难( git rev-list
可以通过 - stdin --no-walk
来设置联合,但似乎没有办法设置交集)。这里有几种找到正确的提交ID的方法,有各种缺点:
<提交和所有提交到达主:
git rev-list --tags --no-walk> / tmp / all-tags
git rev-list master> / tmp / all-master
现在只需打印只出现在两个文件中的行。 comm
实用程序可以执行此操作。它被记录为希望对文件进行排序,但在我看到的所有实现中,文件只需要按照相同顺序排列,因此无需预先排序即可使用 p>
comm -12 / tmp / all-tags / tmp / all-master
pre>
缺点:需要两个临时文件(除非使用特殊的
bash
语法来使用的/ dev / FD
);没有排序可能无法工作;需要comm
。
与以前相同,但使用 uniq -d
来生成列表。 确实需要排序,但是您可以使用管道消除临时文件:
(git rev-list --tags --no-walk; git rev-list master)|排序| uniq -d
缺点:需要排序。提交按一些奇怪的顺序出现,而不是通常用 git log
看到的顺序。
编写你自己的工具,它基本上做了 comm
方法可以做的事情,但是它自己调用 git rev-list
一个使用 mktemp
创建唯一名称的临时文件的脚本)。
缺点:需要更多的工作。 : - )
在所有情况下,一旦您拥有commit-id列表,您只需要通过它们到 git log --no-walk
,例如:
git log --no-walk $(comm -12 / tmp / all-tags / tmp / all-master)
I'd like to git log
all the tagged commits on the master branch (and none of the untagged commits). Is this possible?
The secret trick to this is to realize that git log
uses the same rules as git rev-list
. The latter command has a --tags
flag to look at tags. So, as with the other answers so far, if you're willing to look at all tagged commits, this single command will do it:
git log --no-walk --tags
(The --no-walk
prevents this from starting with tags and finding all their parent commits, and the parents' parents, and so on.)
But you asked for "tagged commits on the master branch", which I assume means (in technical terms) "commits that are both pointed to by tags and reachable via the master
branch". This is substantially harder (git rev-list
can do set union via --stdin --no-walk
, but seems to have no way to do set intersection). Here are several methods of finding the right commit-IDs, with various drawbacks:
First make two file lists: "all tagged commits" and "all commits reachable from master":
git rev-list --tags --no-walk > /tmp/all-tags git rev-list master > /tmp/all-master
Now just print lines that appear only in both files. The
comm
utility can do this. It's documented to expect the files to be sorted, but in all implementations I have seen, the files merely need to be in the same order, as it were, so this works without pre-sorting:comm -12 /tmp/all-tags /tmp/all-master
Drawbacks: needs two temporary files (unless you use the special
bash
syntax that uses/dev/fd
); might not work without sorting; requirescomm
.Same idea as before, but use
uniq -d
to produce the list. This really does require sorting, but you can eliminate the temporary files using a pipe:(git rev-list --tags --no-walk; git rev-list master) | sort | uniq -d
Drawback: requires sorting. The commits come out in some strange order, not the order you would normally see with
git log
.Write your own utility that basically does what the
comm
method would do, but invokesgit rev-list
itself (perhaps a script that creates temp files usingmktemp
to make unique names).Drawback: requires a lot more work. :-)
In all cases, once you have the list of commit-IDs, you just need to pass them to git log --no-walk
, e.g.:
git log --no-walk $(comm -12 /tmp/all-tags /tmp/all-master)
这篇关于一个`git log`标记如何仅提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!