Skip to content

Instantly share code, notes, and snippets.

@sinelaw
Created May 21, 2018 04:32
Show Gist options
  • Save sinelaw/bdb7e4c1cc3fdbe7946f32fce1e43f71 to your computer and use it in GitHub Desktop.
Save sinelaw/bdb7e4c1cc3fdbe7946f32fce1e43f71 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
BRANCH_A="$1"
shift
BRANCH_B="$1"
shift
PATHS="$@"
BRANCH_A_COMMITS=$(mktemp)
ONLY_IN_BRANCH_A=$(mktemp)
BRANCH_B_COMMITS=$(mktemp)
ONLY_IN_BRANCH_B=$(mktemp)
git log --format="%s" ${BRANCH_A} -- ${PATHS} > ${BRANCH_A_COMMITS}
git log --format="%s" ${BRANCH_B} -- ${PATHS} > ${BRANCH_B_COMMITS}
if grep -vFf "${BRANCH_B_COMMITS}" "${BRANCH_A_COMMITS}" > ${ONLY_IN_BRANCH_A} ;
then
echo "Only in ${BRANCH_A}:"
git log --format="%h %an: %s" ${BRANCH_A} | grep -Ff ${ONLY_IN_BRANCH_A}
fi
if grep -vFf "${BRANCH_A_COMMITS}" "${BRANCH_B_COMMITS}" > ${ONLY_IN_BRANCH_B} ;
then
echo "Only in ${BRANCH_B}:"
git log --format="%h %an: %s" ${BRANCH_B} | grep -Ff ${ONLY_IN_BRANCH_B}
fi
rm ${ONLY_IN_BRANCH_B}
rm ${BRANCH_B_COMMITS}
rm ${ONLY_IN_BRANCH_A}
rm ${BRANCH_A_COMMITS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment