Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to extract filenames from git whatchanged

Tags:

git

bash

I'm trying to get a list of all the js files that changed to know what to reminify.

I previously asked this question

So far this is the best I came up with but it feels really unsafe.

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

But this gives me all the files that changed (php css js) and not just the js files

How would I get just the js files? Also is there a better way to accomplish this?

like image 934
qwertymk Avatar asked Dec 05 '25 11:12

qwertymk


1 Answers

From this answer, use git show --pretty="format:" --name-only HEAD^ to get a list of changed files. Then pipe it through grep.

git show --pretty="format:" --name-only HEAD^ | grep '\.js$'
like image 144
Schwern Avatar answered Dec 07 '25 00:12

Schwern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!