如何按拓扑顺序对一组git commit ID进行排序? [英] How can I sort a set of git commit IDs in topological order?
问题描述
我有一组提交SHA1,没有特定顺序.我想将此设置通过管道传递给命令,并以拓扑顺序返回这些提交.
这是执行此操作的一种方法:
git rev-list --all --topo-order |grep-文件SET_OF_SHA1S
您可以想象,这是一种非常慢的方法,因为 git rev-list
必须打印出所有提交的SHA1,而不仅仅是我的集合中的./p>
是否有更好,更快的方法来做到这一点?
用例:
我的测试框架测试某些Git提交并将结果存储在数据库中.我正在写一个总结这些结果的网页,最好按顺序显示结果.按提交日期排序不是理想的方法,因为某些基于重新定位的提交将具有完全相同的提交日期.
这是一种加快速度的方法:
git rev-list --topo-order $(cat SET_OF_SHA1S)\|grep-文件SET_OF_SHA1S-最大计数$(wc -l SET_OF_SHA1S)
优化:
- 仅要求
rev-list
列出您的SHA1组中所有可到达的提交. - 一旦
rev-list
打印出足够多的提交,其中包括您感兴趣的SHA1集,请告诉grep
使用停止grepping-max-count
参数.grep
将依次关闭其输入,而rev-list
将停止不必要地打印出其他SHA1.
I have a set of commit SHA1s, in no particular order. I would like to pipe this set to a command, and have those commits returned in topological order.
Here's one way of doing this:
git rev-list --all --topo-order | grep --file SET_OF_SHA1S
As you can imagine, this is a very slow way of doing it, as git rev-list
is having to print out all of the commit SHA1s, not just the ones in my set.
Is there a better and faster way to do this?
Use case:
My test framework tests certain Git commits and stores the result in a database. I'm writing a web page that summarises these results, and it would be nice to display the results in order. Sorting by commit date is not ideal as some rebased commits will have exactly the same commit date.
Here's one way of speeding it up:
git rev-list --topo-order $(cat SET_OF_SHA1S) \
| grep --file SET_OF_SHA1S --max-count $(wc -l SET_OF_SHA1S)
Optimisations:
- Only ask
rev-list
to list all commits reachable from your set of SHA1s. - As soon as
rev-list
prints enough commits that include the set of SHA1s you're interested in, tellgrep
to stop grepping using the--max-count
parameter.grep
will in turn close its input, andrev-list
will stop needlessly printing out further SHA1s.
这篇关于如何按拓扑顺序对一组git commit ID进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!