Git run shell command for each commit

Solution 1:

You can use interactive rebase with an exec option.

git rebase -i --exec <build command> <first sha you want to test>~

--exec Append "exec " after each line creating a commit in the final history. will be interpreted as one or more shell commands.

Reordering and editing commits usually creates untested intermediate steps. You may want to check that your history editing did not break anything by running a test, or at least recompiling at intermediate points in history by using the "exec" command (shortcut "x").

The interactive rebase will stop when a command fails (i.e. exits with non-0 status) to give you an opportunity to fix the problem.

Solution 2:

You probably want rev-list.

#!/usr/bin/env bash
# test_commits.sh

while read -r rev; do
    git checkout "$rev"
    if ! git submodule update && make clean && make; then
        >&2 echo "Commit $rev failed"
        exit 1
    fi
done < <(git rev-list "$1")

Then you can use it with

./test_commits.sh origin/master..master