Last active
January 19, 2019 10:00
-
-
Save machta/e259c5706e6f29d43b04cbdf37dd17a8 to your computer and use it in GitHub Desktop.
Compares all commits in a git repo against a directory, and outputs the commit message prefixed by the line count of the diff between the two
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: ./git-compare.sh PATH_TO_REPO DIR_TO_COMPARE_AGAINST | |
# | |
# Compares all commits in a git repo against a directory, and outputs the commit | |
# message prefixed by the line count of the diff between the two. | |
# | |
# If somobody copies the content of your repository (i.e. downloads a tarball | |
# instead of cloning it) and possibly does some changes, you can later use this | |
# to figure out on which commit it was based on. | |
# | |
# `diff -r` is used to do the comparison. ".git" is excluded from the diff. | |
# This probably means that changes in files like .gitignore will not count. | |
REPO=`realpath $1` | |
DIFF_TO=`realpath $2` | |
cd $REPO | |
COMMIT_HASHES=`git log --pretty=format:"%h"` | |
ORIGINAL_COMMIT=`git log --pretty=format:"%h" | head -1` | |
do_work() { | |
for h in $COMMIT_HASHES ; do | |
git checkout $h 2>/dev/null | |
printf "%8s %s\n"\ | |
`diff -r -x '.git' --suppress-common-lines --new-file\ | |
$REPO $DIFF_TO | wc -l`\ | |
"`git log --oneline | head -1`" | |
done | |
} | |
# Trims the output to fit into a terminal | |
do_work | cut -c-`tput cols` | |
# FIXME This returns to the right commit, but you are detached | |
git checkout $ORIGINAL_COMMIT 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment