git - 显示已更改文件的文件名和文件大小?

Ter*_*den 4 git

有什么方法可以查看差异上的新文件大小吗?

如果我跑步git diff --name-only我会得到

path/to/changed/file.1
path/to/changed/file.2
path/to/changed/file.3
Run Code Online (Sandbox Code Playgroud)

我想要看到的是:

path/to/changed/file.1 1.7KB
path/to/changed/file.2 300Bytes
path/to/changed/file.3 9MB
Run Code Online (Sandbox Code Playgroud)

我可以运行git diff --name-only | xargs ls -l,但这也给了我文件权限、日期等。

有内置git diff命令来显示文件大小吗?

Moh*_*asi 5

这样:

git diff --name-only
Run Code Online (Sandbox Code Playgroud)

你应该得到:

path/to/changed/file.1
path/to/changed/file.2
path/to/changed/file.3
Run Code Online (Sandbox Code Playgroud)

由于此命令显示相对于项目根目录的更改文件,因此您必须将目录更改为项目的根目录(例如文件 .gitignore 存在的位置)。
现在,除了运行以下命令之外,您还可以获取每个更改文件的大小:

git diff --name-only  | xargs du -hs
Run Code Online (Sandbox Code Playgroud)

示例输出为:

5.0K    path/to/changed/file.1
15.0K   path/to/changed/file.2
14.0K   path/to/changed/file.3
Run Code Online (Sandbox Code Playgroud)

如果您想要您最喜欢的结果,请运行以下命令:

git diff --name-only  | xargs du -hs | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }'
Run Code Online (Sandbox Code Playgroud)

和输出:

path/to/changed/file.1  5.0K
path/to/changed/file.2  15.0K
path/to/changed/file.3  14.0K
Run Code Online (Sandbox Code Playgroud)