I want to list all commits that are only part of a specific branch.
With the following, it lists all the commits from the branch, but also from the parent (master)>
This will output the commits on the current branch. If any argument is passed, it just outputs the hashes.
#!/bin/bash
function show_help()
{
ME=$(basename $0)
IT=$(cat < default. compares current branch to master
$ME B1 -> compares branch B1 to master
$ME B1 B2 -> compares branch B1 to B2
$ME B1 B2 V -> compares branch B1 to B2, and displays commit messages
)
echo "$IT"
exit
}
if [ "$1" == "help" ]
then
show_help
fi
# Show commit msgs if any arg passed for arg 3
if [ "$3" ]
then
OPT="-v"
fi
# get branch names
OLDER_BRANCH=${2:-"master"}
if [ -z "$1" ]
then
NEWER_BRANCH=$(git rev-parse --abbrev-ref HEAD)
else
NEWER_BRANCH=$1
fi
if [ "$NEWER_BRANCH" == "$OLDER_BRANCH" ]
then
echo " Please supply 2 different branches to compare!"
show_help
fi
OUT=$(\git cherry $OPT $OLDER_BRANCH $NEWER_BRANCH)
if [ -z "$OUT" ]
then
echo "No differences found. The branches $NEWER_BRANCH and $OLDER_BRANCH are in sync."
exit;
fi
if [ "$OPT" == "-v" ]
then
echo "$OUT"
else
echo "$OUT" | awk '{print $2}'
fi