Skip to content

Instantly share code, notes, and snippets.

@ThrashAbaddon
Forked from jotaelesalinas/git-squash.bat
Created April 25, 2017 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThrashAbaddon/e790945befe7035f1ef3737aa02270e1 to your computer and use it in GitHub Desktop.
Save ThrashAbaddon/e790945befe7035f1ef3737aa02270e1 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!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment