Last active
January 12, 2019 05:43
-
-
Save elliotthilaire/d90f2ed0107b3a9791b08ee4da276783 to your computer and use it in GitHub Desktop.
A bash script to run a command against different branches or commits automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# ./compare-branches.sh "./some-command arg-1 arg-2" branch-1 branch-2 | |
# | |
# https://twitter.com/elliotthilaire/status/1083859808086720512 | |
# Thanks to @schneems, @tosbourn, and @matthewrudy for their input. | |
current_branch=$(git symbolic-ref --short HEAD) | |
command=$1 | |
commits=${@:2} | |
echo "running $command on $commits" | |
echo "----------------------------------------" | |
for commit in $commits | |
do | |
$(git checkout $commit) | |
eval $command | |
echo "----------------------------------------" | |
done | |
$(git checkout $current_branch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment