New paste Repaste Download
# use it as: > squash_last_n_commits 2
squash_last_n_commits()
{
if [ $# -ne 1 ] || [ "$1" -lt 2 ]; then
echo 'squash_last_n_commits() requires a number (>1) as the only argument ("HEAD~$1")'
else
echo "Creating '__pre_squash__state__' tag, just in case."
git tag "__pre_squash__state__"
git reset --soft HEAD~$1 &&
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
if [ $? -ne 0 ]; then
echo "Squash operation aborted. Resetting to previous state."
git reset "__pre_squash__state__"
fi
git tag -d "__pre_squash__state__"
fi
}
Filename: None. Size: 591b. View raw, , hex, or download this file.

This paste expires on 2025-01-22 19:23:56.351403. Pasted through web.