Skip to content

Instantly share code, notes, and snippets.

@amgohan
Created May 1, 2018 00:05
Show Gist options
  • Save amgohan/ab95c608d0dfc83ac531a84866632993 to your computer and use it in GitHub Desktop.
Save amgohan/ab95c608d0dfc83ac531a84866632993 to your computer and use it in GitHub Desktop.
Squash the last 'n' commits
#!/bin/sh
# usage : squash 3 "new comment to replace the 3 last commits"
active_branch=$(git branch | head -n 1)
branch_name=${active_branch:2}
commits_to_squash=$1
new_commit_message=$2
git reset --soft HEAD~${commits_to_squash}
git commit -am "${new_commit_message}"
git push origin +${branch_name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment