Last Updated: February 25, 2016
·
696
· hemanth

git squash commits

Add the below to your .bashrc or similar :

function gsq(){
  git reset --soft HEAD~$1 && \
  git commit --edit -m \
  "$(git log --format=%B --reverse HEAD..HEAD@{1})"
}

then you can use gsq 3 to squash the last three commits to one.

3 Responses
Add your response

I think the correct syntax for this function declaration should be function gsq()

You want to get only the first parameter anyway...

over 1 year ago ·

Heh heh right, I'm using $1 anyway :)

over 1 year ago ·

Seems there would be a way to put this in as a git alias (like the popular 'lg' one).

over 1 year ago ·