I know how to swap the last two commits using git rebase interactively (git rebase -i HEAD~2, ddjp:x in Vim), but I\'d like to do it p
For reference, this is the script I ended up using:
. "$(git --exec-path)/git-sh-setup"
require_clean_work_tree swap2
if [ -e $GIT_DIR/sequencer ]; then
die "Cherry-pick already in progress; swap aborted"
fi
HEAD=`git rev-list --max-count=1 HEAD`
git reset --hard HEAD~2
if git cherry-pick $HEAD $HEAD^; then
echo "Successfully swapped top two commits."
else
git cherry-pick --abort
git reset --hard $HEAD
die "Failed to swap top two commits."
fi