public
anonymous / linear-git-history.sh
Created

Linear walk of git history

  • Download Gist
linear-git-history.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/bash
#Example usage: linear-git-history.sh HEAD FETCH_HEAD
 
prev_commit=$1
end_commit=$2
git log --pretty=format:"%h%n" --ancestry-path --reverse $prev_commit..$end_commit | while read commit; do
if [ -n "$commit" ]; then
 
#We need to make sure the commit is a direct child of the previous commit.
is_direct_child=$(git show -s --pretty=format:"%P" $commit | grep $prev_commit)
if [ ! -z "$is_direct_child" ] ; then
echo "$commit"
else
echo "The commit is not a direct decendant of $prev_commit"
fi
 
prev_commit=$commit
fi
done

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.