如何在Git存储库中列出目录以及每个目录条目的最新提交信息? [英] How do I list a directory in a Git repository together with the latest commit info for each directory entry?
问题描述
我想列出Git存储库中的目录以及每个目录条目的最新提交信息.与GitHub如何显示目录或viewvc如何在SVN/CVS存储库中显示目录类似.
I want to list a directory from a Git repository together with the latest commit information of each directory entry. Similiar to how GitHub displays directories or how viewvc displays a directory in an SVN/CVS repository.
目前我是这样的:
-
使用
git ls-tree master
获取目录条目,并从输出中解析目录结构.
Get the directory entries with
git ls-tree master
and parse the directory structure from the output.
然后为每个目录条目执行此操作:git log -n 1 master -- filename
并从中解析提交信息(我指定了一种特殊格式的字符串来简化此操作,但这与我的问题无关). p>
Then for each directory entry I do this: git log -n 1 master -- filename
and parse the commit information from it (I specify a special format string to make this easier, but this isn't relevant to my problem).
很明显,这非常慢,因为我必须为每个文件调用Git.有没有更快的方法可以做到这一点?也许我可以执行一条命令一次获取所有我需要的数据?
It's pretty obvious that this is very slow, because I have to call Git for each file. Is there a faster way to do this? Maybe a single command I can execute to get all the data I need at once?
推荐答案
Oneliner解析git whatchanged
输出并打印带有最近提交ID的树:
Oneliner to parse git whatchanged
output and print tree annotated with recent commit ids:
git whatchanged -r --pretty=oneline | perl -ne 'our %q; if (/^([0-9a-f]{40})/) {$c = $1} if (/:.{38}(.*)/) { $q{$1} = $c unless exists $q{$1} }; END { print map {"$q{$_} $_\n"} (keys %q); }' | sort -k 2
示例输出:
b32f7f65f19e547712388d2b22ea8d5355702ce2 code/unfreezemodule/file.c
b32f7f65f19e547712388d2b22ea8d5355702ce2 code/unfreezemodule/Makefile
b32f7f65f19e547712388d2b22ea8d5355702ce2 code/unfreezemodule/unfreezemodule.c
efeda0a22e4d1d5f3d755fee5b72fa99c0046e38 code/unfreezer/.gitignore
b822361ffbc4548d918df5381ce94c296459598a code/unfreezer/unfreezer.c
18ed76836182eba702e89b929eff2c0ea78ffb3e code/whole/wh
1e111ce4e8c0813b397f34e3634309f7594cb864 code/xbmctest/.gitignore
cb67943c4c18e3461267a34935fc8efaca5e2166 .config/awesome/awesome.lua
d5e2b7c1d24bed1d0b53338f43747dc856c9cfe4 .config/awesome/rc.lua
13ca8dbcd7f1ec684a7eba494442ee743ed577c0 cr
566b54fb72e32947fcbf7d5c58fed78b5abe976d d
392ac1a2456e8a29b2ebb7af9499c3f69d24a559 Desktop/CityInfo.desktop
392ac1a2456e8a29b2ebb7af9499c3f69d24a559 Desktop/.directory
您可以根据需要调整git whatchanged
参数和/或过滤输出.
You can adjust git whatchanged
parameters and/or filter the output as you want.
这篇关于如何在Git存储库中列出目录以及每个目录条目的最新提交信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!