Skip to content

Instantly share code, notes, and snippets.

@rrdelaney
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrdelaney/f587ec22133f12fdfe4c to your computer and use it in GitHub Desktop.
Save rrdelaney/f587ec22133f12fdfe4c to your computer and use it in GitHub Desktop.
Rebaseify!
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo "Rebasify!"
echo "Usage"
echo "rebaseify start"
echo " generates commit log for editing"
echo ""
echo "rebaseify finish"
echo " rebases on the edited commit log"
fi
force=''
if test "x$1" = "x-f"; then
force='-f'
shift
fi
commits=$(git log --pretty=format:'"%H": {"author": {"name": "%an"}, "date": "%cd"},')
filter='
export GIT_COMMITER_DATE=$(node -p "require(\"./../../commits\")[\"$GIT_COMMIT\"].date")
export GIT_AUTHOR_DATE=$(node -p "require(\"./../../commits\")[\"$GIT_COMMIT\"].date")
export GIT_AUTHOR_NAME=$(node -p "require(\"./../../commits\")[\"$GIT_COMMIT\"].author.name")
'
if [[ $1 = "start" ]] ; then
printf "{\n${commits%?}\n}\n" > commits.json
fi
if [[ $1 = "finish" ]] ; then
git filter-branch $force --env-filter "$filter" -- "$(git rev-parse --abbrev-ref HEAD)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment