如何在git存储库中列出跟踪文件的所有不同扩展名? [英] How to list all distinct extensions of tracked files in a git repository?

查看:125
本文介绍了如何在git存储库中列出跟踪文件的所有不同扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在给定的回购库中由git跟踪的文件的所有不同的扩展,以便创建适当的 .gitattributes 文件。



预期输出示例:

  bat 
gitignore
gradle
html
jar
java
js
json
md
png
属性
py
svg
webp
xml
yml

什么命令我可以使用它吗?

解决方案

  git ls-tree -r HEAD --name -only | perl -ne'打印$ 1 if m / \。([^。\ /] +)$ /'| sort -u 

当您将其声明为别名时,必须将 $ 1

  alias gitFileExtensions =git ls-tree -r HEAD --name-only | perl -ne'print \ $ 1 if m / \。([^。\ /] +)$ /'| sort -u

这比天真的 find 要好,因为:


  • 它排除了未跟踪的(gitignored)文件
  • 它不包含 .git 通常包含数百/因此减慢了搜索速度。



(受>如何在文件夹层次结构中找到所有不同的文件扩展名?


I'd like to know all distinct extensions of files tracked by git in a given repo, in order to create appropriate .gitattributes file.

Example output expected:

bat
gitignore
gradle
html
jar
java
js
json
md
png
properties
py
svg
webp
xml
yml

What command can I use for that?

解决方案

git ls-tree -r HEAD --name-only | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u 

When you declare it as an alias, you have to escape $1:

alias gitFileExtensions="git ls-tree -r HEAD --name-only | perl -ne 'print \$1 if m/\.([^.\/]+)$/' | sort -u"

This is better than naive find, because:

  • it excludes untracked (gitignored) files
  • it excludes .git directory which contains usually hundreds/thousands of files and hence slows down the search

(inspired by How can I find all of the distinct file extensions in a folder hierarchy?)

这篇关于如何在git存储库中列出跟踪文件的所有不同扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆