Skip to content

Instantly share code, notes, and snippets.

@kicumkicum
Last active June 25, 2020 11:49
Show Gist options
  • Save kicumkicum/bc0de6426933450f4cb323660bde742a to your computer and use it in GitHub Desktop.
Save kicumkicum/bc0de6426933450f4cb323660bde742a to your computer and use it in GitHub Desktop.
next-commit
#!/usr/bin/env bash
if [ -n "$1" ]; then
echo "You supplied the first parameter!"
else
echo "Parameters not supplied."
exit 1
fi
MODULE=$1
TARGET=module-${MODULE}
PREFIX=bb
OLD_BRANCH=$(git branch --show-current)
## GET FIRST COMMIT
if [ -n "$2" ]; then
HASH_CURRENT=$2
else
git checkout - -f
if [[ "${OLD_BRANCH}" == "${PREFIX}"* ]]; then
git branch -D ${OLD_BRANCH}
fi
HASH_CURRENT=$(git log --oneline HEAD..${TARGET} --pretty="%h" |tail -1)
fi
echo Current hash: ${HASH_CURRENT}
## GET SECOND COMMIT
git checkout ${HASH_CURRENT}
HASH_NEXT=$(git log --oneline HEAD..${TARGET} --pretty="%h" |tail -1)
if [[ -n "${HASH_NEXT}" ]]; then
echo ""
else
echo "HASH_NEXT IS EMPTY"
exit 1
fi
echo Next hash: ${HASH_NEXT}
## CREATE TMP BRANCH WITH DIFF
git checkout -f
git checkout -b ${PREFIX}-${HASH_NEXT}
git merge --no-ff --no-commit ${HASH_NEXT}
git status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment