我正在尝试获取所有已更改的 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 文件?还有没有更好的方法来实现这一点?
最佳答案
来自 this answer ,使用 git show --pretty="format:"--name-only HEAD^
获取已更改文件的列表。然后通过 grep
将其通过管道传输。
git show --pretty="format:" --name-only HEAD^ | grep '\.js$'
关于git - 从 git 中提取文件名的 Bash 脚本发生了什么变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9371077/