Skip to content

Instantly share code, notes, and snippets.

@wancw
Last active August 29, 2015 14:04
Show Gist options
  • Save wancw/4feaf7388c2dbc42fadb to your computer and use it in GitHub Desktop.
Save wancw/4feaf7388c2dbc42fadb to your computer and use it in GitHub Desktop.
Utils for merged branch
#!/bin/sh
export FMC_WRAPPER=`basename $0`
MERGE_COMMIT=`git find-merge-commit $*`
if [[ $? != 0 ]]; then
exit $?
fi
git branch --all --contain $MERGE_COMMIT
#!/bin/sh
if [[ "$#" < 1 || "$#" > 2 ]]; then
echo "Usage:\t${FMC_WRAPPER:-`basename $0`} [<pattern> [<mainstream branch>]]" >&2
exit 1
fi
BRANCH_NAME_PATTERN="$1"
MAINSTREAM_BRANCH="$2"
if [[ "$MAINSTREAM_BRANCH" == "" ]]; then
MAINSTREAM_BRANCH="master"
fi
declare -a MERGE_COMMITS
LOG_GREP_PATTERN="^Merge.+$BRANCH_NAME_PATTERN.+ to $MAINSTREAM_BRANCH"
MERGE_COMMITS=(`git log --format=format:%h -E --grep "$LOG_GREP_PATTERN"`)
COMMIT_COUNT=${#MERGE_COMMITS[@]}
if [[ $COMMIT_COUNT > 1 ]]; then
echo "More than one merge matched:" >&2
for (( i = 0; i < $COMMIT_COUNT; i++ )); do
git log --oneline -1 ${MERGE_COMMITS[$i]} >&2
done
exit 1
fi
echo ${MERGE_COMMITS[0]}
#!/bin/sh
export FMC_WRAPPER=`basename $0`
MERGE_COMMIT=`git find-merge-commit $*`
if [[ $? != 0 ]]; then
exit $?
fi
git log --oneline --graph ^$MERGE_COMMIT^1 $MERGE_COMMIT^2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment