Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Easy git-squash (merges last N commits in one)
@echo off
if "%1"=="" goto blank
echo Squashing %1 commits...
git reset --soft HEAD~%1
git log --format=%%B%%n --reverse "HEAD@{1}" -n %1 > _msg.txt
git commit -t _msg.txt
del _msg.txt
echo Done!
goto end
:blank
echo Missing parameter: number of commits to squash.
exit /B 1
:end
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Missing parameter: number of commits to squash."
exit 1
fi
echo "Squashing $1 commits..."
git reset --soft HEAD~$1
git log --format=%B%n --reverse "HEAD@{1}" -n $1 > _msg.txt
git commit -t _msg.txt
rm _msg.txt
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment