Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2011 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1096180 to your computer and use it in GitHub Desktop.
Save anonymous/1096180 to your computer and use it in GitHub Desktop.
Linear walk of git history
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment