我正在尝试获取所有js文件的列表,这些文件已更改为知道要提醒的内容。
我之前曾问过this问题
到目前为止,这是我提出的最好的,但感觉真的不安全。
GITCHANGES=$(git whatchanged -n 1 --pretty=format:)
I=0;
for f in $GITCHANGES;
do
I=$(($I + 1));
if [[ $(($I % 6 )) == 0 ]]; then
echo "$f"
fi
done
但这会为我提供所有已更改的文件(php
css
js
),而不仅仅是js
个文件
我如何获得js文件?还有更好的方法来实现这个目标吗?
答案 0 :(得分:3)
从this answer,使用git show --pretty="format:" --name-only HEAD^
获取已更改文件的列表。然后通过grep
管道。
git show --pretty="format:" --name-only HEAD^ | grep '\.js$'
答案 1 :(得分:1)
您的脚本可以简单地压缩到
中git diff-tree --name-only HEAD^ HEAD | grep '\.js$'
这将列出所有。{1}}(第一个父级)和HEAD^
之间不同的.js文件列表。