git - git - 显示更改文件的文件名和文件大小?
问题描述
有什么方法可以在差异上查看新文件大小?
如果我跑,git diff --name-only
我会得到
path/to/changed/file.1
path/to/changed/file.2
path/to/changed/file.3
我想看到的是:
path/to/changed/file.1 1.7KB
path/to/changed/file.2 300Bytes
path/to/changed/file.3 9MB
我可以运行git diff --name-only | xargs ls -l
,但这也给了我文件权限、日期等。
是否有内置git diff
命令来显示文件大小?
解决方案
这样:
git diff --name-only
你应该得到:
path/to/changed/file.1
path/to/changed/file.2
path/to/changed/file.3
由于此命令显示相对于项目根目录的更改文件,因此您必须将目录更改为项目的根目录(例如,文件 .gitignore 所在的位置)。
现在您还可以通过运行以下命令获得每个更改文件的大小:
git diff --name-only | xargs du -hs
示例输出为:
5.0K path/to/changed/file.1
15.0K path/to/changed/file.2
14.0K path/to/changed/file.3
如果你想要你最喜欢的结果,运行这个:
git diff --name-only | xargs du -hs | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }'
和输出:
path/to/changed/file.1 5.0K
path/to/changed/file.2 15.0K
path/to/changed/file.3 14.0K
推荐阅读
- r - 编写小插图时如何使用 R 包自己的数据
- jenkins - 是否有从 Jenkins 多分支管道中的选择参数中选择 ALL 的选项
- javascript - 为什么 Chrome 和 Safari 在 iOS 上两次请求位置权限?
- android - 在 Android 应用程序中使用使用 R 设计的预测模型
- ios - Unity 聊天应用程序
- database - 想要选择表格的前 1 行
- python - 我需要帮助来创建一个自动食品订购系统
- java - 如何从 Spring Boot 项目中获取当前的 thymeleaf 版本?
- html - SVG rect 覆盖视口
- python - 如何检查 distutils 是否已正确安装和使用?