Skip to content

Instantly share code, notes, and snippets.

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
echo Missing parameter: number of commits to squash.
exit /B 1
if [ $# -ne 1 ]; then
echo "Missing parameter: number of commits to squash."
exit 1
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!"
Copy link

kkm000 commented Nov 3, 2017

Thanks, that's a simple approach! One caveat is that this way you do not keep the original commit author and e-mail.

Copy link

jotaelesalinas commented Sep 21, 2018

True. You become the owner of all the squashed changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment