Skip to content

Instantly share code, notes, and snippets.

@jotaelesalinas
Last active April 7, 2021 17:05
Show Gist options
  • Save jotaelesalinas/a1f7a3c3477c5805411c7f739e29d50c to your computer and use it in GitHub Desktop.
Save jotaelesalinas/a1f7a3c3477c5805411c7f739e29d50c to your computer and use it in GitHub Desktop.
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!"
@kkm000
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.

@jotaelesalinas
Copy link
Author

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