简体   繁体   English

使用git rev-list打印分支名称

[英]Print branch name with git rev-list

I'm writing a script and I need to feed it with a paging list of branches in a repo. 我正在写一个脚本,我需要用回购中的分支页面列表来提供脚本。

The only git command I could find that can handle refs with a --max-count and a --skip parameter, which are the essential components of paging results, is a rev-list . 我可以找到的唯一可以处理带有--max-count--skip参数的引用的git命令是rev-list ,这是分页结果的基本组成部分。 But I can't find an equivalent to the refname for the --format argument of rev-list . 但是我找不到与rev-list--format参数的refname等效rev-list

This is what I'm trying to do but with a git for-each-ref instead: 这是我想要做的,但是使用git for-each-ref代替:

git for-each-ref --sort=-committerdate refs/heads/ \
       --format='%(refname:short) %(objectname:short)'

Unfortunately neither git for-each-ref nor git branch have a --skip for paging (only a --count ), so it's no good for my paging script. 不幸的是git for-each-refgit branch都没有--skip来进行分页(只有--count ),所以这对我的分页脚本没有好处。

I'm also trying to do this using one command. 我也在尝试使用一个命令来执行此操作。 Using nested/piped commands has a performance hit I'm not willing to take due to the fact that this will run against a long list of historical branches and needs to process by a pages. 使用嵌套/管道命令会降低性能,因为我不愿意这样做,因为它会与一长串的历史分支相对应,并且需要按页面进行处理。 But I'm open to suggestions. 但我愿意提出建议。

Every ref points to one and only one commit, which is why for-each-ref can be made to act on commit attributes. 每个引用都指向一个且只有一个提交,这就是为什么可以使for-each-ref对提交属性起作用的原因。

But the converse is not true. 但是反过来是不正确的。 Some commits have no refs pointing at them. 有些提交没有引用指向他们。 Some commits have many refs pointing at them. 一些提交有很多引用指向他们。 So asking rev-list to act on ref (eg branch) attributes is inherently ambiguous. 因此,要求rev-list对ref(例如branch)属性进行操作本质上是模棱两可的。

I think your best bet is to run for-each-ref once, capturing the output to a set of pre-paged files. 我认为最好的选择是运行一次for-each-ref ,将输出捕获到一组预先分页的文件中。 Yes the initial run to create the files will involve piped processes ( git for-each-ref piped to a script that splits out a file for each page); 是的,创建文件的初始运行将涉及管道处理(将git for-each-ref管道传输至脚本,该脚本为每个页面拆分出一个文件); but then requests for individual pages will actually be faster because they won't even have to invoke git. 但是对单个页面的请求实际上会更快,因为它们甚至不必调用git。

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

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