Bash script to extract filenames from git whatchanged

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

I previously asked this question

  • quitting git log from a bash script
  • git post-commit hook - script on committed files
  • Parse git log file names to json
  • fatal: Authentication failed Git Bash
  • Append git's branch name to command prompt
  • Bash: How to compose functions where the inner function will return an argument
  • So far this is the best I came up with but it feels really unsafe.

    GITCHANGES=$(git whatchanged -n 1 --pretty=format:)
    for f in $GITCHANGES;
        I=$(($I + 1));
        if [[ $(($I % 6 )) == 0 ]]; then
            echo "$f"

    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?

  • Merge using EGit results in commit of all changes as done by the merger
  • Git merge strategy 'theirs' is not resolving modify/delete conflict
  • Are there any problems if using a shared repository between SVN and Git, without git-svn?
  • How to import a GIT non-Eclipse Java project into Eclipse?
  • What a git SHA depends on?
  • Only Single GitLab CI Runner Building
  • 2 Solutions collect form web for “Bash script to extract filenames from git whatchanged”

    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$'

    Your script can be condensed really simply into

    git diff-tree --name-only HEAD^ HEAD | grep '\.js$'

    This will spit out a list of all .js files that differ between HEAD^ (first parent) and HEAD.

    Git Baby is a git and github fan, let's start git clone.