使用简单的git命令或shell脚本计算GIT存储库中每个子目录内部的分区数量
我有一个带有以下结构的存储库,我会像tier1,tier2和tier3内的子目录伯爵。我不想在子目录中计算子目录。例如,我的文件夹在tier1内部名为1、2、3,我想把计数视为3。我不想要什么1,2,3文件夹。
应该避免GIT克隆动作,因为我们不需要整个仓库中的本地克隆以及所有历史记录信息。一个简单的获取就足够了,是否有任何更精简的方法来检索目录信息?
AM目前通过输入每个文件夹和Folloing命令来计数子目录数量:
ls | wc -l
I have a repo with the following structure and I wouldlike to countnumber of subdirectories inside tier1, tier2 and tier3. I dont want to count subdirectories within the subdirectory. For examplee i have folders named a 1, 2, 3 inside tier1 and i wanted to see the count as 3. I dont want whats isnide those 1,2,3 folders.
Git clone actions should be avoided, as we do not need a local clone of the whole repo plus all history information. A simple fetch will be enough, is there are any leaner ways to retrieve the directory information ??
Am presently counting number of subdirectories by, entering each folder and the folloing command:
ls | wc -l
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以过滤克隆以跳过实际内容,只需获得结构即可。对于Linux存储库,这是一个约25m的下载,节省了〜99%:
列出高级目录,然后只是一个格式的问题,
You can filter your clones to skip the actual content, just get the structure. For the linux repo this is a ~2.5M download, a ~99% savings:
lists the toplevel directories, then it's just a formatting question,
ls
充其量只能为您提供直接在目录内的非隐藏条目的数量。如果您有一个普通文件,或一个包含空格的条目,或一个名称带有周期的名称的条目,或者是目录的目录条目,但本身具有子目录,则您的计数将是错误的。相反,我会执行
设置
nullglob
的目的仅是为了避免出现错误消息,如果存在tier
目录。更新:如果您对子目录不感兴趣,则可以执行
查找
adotglob 确保您不会丢失隐藏的子目录,以及最终的斜线全球模式可确保扩展仅用于表示目录的条目。
ls
at best gives you the number of non-hidden entries directly inside the directory. If you have among them a plain file, or an entry containing spaces, or an entry where the name strats with a period, or a directory entry which is a directory, but has itself subdirectories, your count will be wrong.I would instead do a
The purpose of setting
nullglob
is only to avoid an error message if notier
directory exists.UPDATE: If you are not interested in subdirectories further down, you could do instead of the
find
aThe dotglob ensures that you are not missing hidden subdirectories, and the final slash in the glob-pattern ensures that the expansion happens only for entries which denote a directory.
您可以将
head
替换为任何commit-ish参考:如果您想要 all (递归)子目录的列表,请添加
-r
选项。you can replace
HEAD
with any commit-ish reference :If you want the list of all (recursive) subdirectories, add the
-r
option.