Skip to content

Instantly share code, notes, and snippets.

@pivotaljohn
Created May 4, 2016 23:02
Show Gist options
  • Save pivotaljohn/8bd5dd88cc98e1c5381d5128d81828a1 to your computer and use it in GitHub Desktop.
Save pivotaljohn/8bd5dd88cc98e1c5381d5128d81828a1 to your computer and use it in GitHub Desktop.
Reset author information to be the duet pair after a rebase.
#!/usr/bin/env bash
function usage_and_quit() {
echo "Reset author for specified ref through to HEAD to the current duet pair."
echo ""
echo "Usage:"
echo " $0 (base ref)"
exit 1
}
function confirm_or_quit() {
read -p "Are you sure (y/N)? " -n 1 -r; echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborting."
exit 1
fi
}
if [ "$1" == "" ]; then
usage_and_quit
fi
echo "About to reset author to ..."
git duet
echo -e "\nfor these commits..."
echo "----"
git lol $1..HEAD
echo "----"
echo "WARNING: This command rewrites history. If you have already pushed to a shared repo (e.g. GitHub)"
echo " You will have to force push to affect the changes you make (a move that is widely frowned upon)."
confirm_or_quit
git filter-branch --env-filter "$( git duet )" $1..HEAD
echo -e "\n\ngit filter-branch added a ref for you as a backup pointing to the old set of commits."
echo "once you are convinced the right thing happened you can clean-up that ref with:"
echo
echo "$ git update-ref -d (full ref-name here)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment