Skip to content

Instantly share code, notes, and snippets.

@alex-mtx
Created September 4, 2017 13:32
Show Gist options
  • Save alex-mtx/c34c6fbc981cbea13ddb0f38f84236f4 to your computer and use it in GitHub Desktop.
Save alex-mtx/c34c6fbc981cbea13ddb0f38f84236f4 to your computer and use it in GitHub Desktop.
Git squash made simple for Master
Thanks to: https://stackoverflow.com/a/5201642/1456567
You can do this fairly easily without git rebase or git merge --squash. In this example, we'll squash the last 3 commits.
If you want to write the new commit message from scratch, this suffices:
git reset --soft HEAD~3 &&
git commit
If you want to start editing the new commit message with a concatenation of the existing commit messages (i.e. similar to what a pick/squash/squash/…/squash git rebase -i instruction list would start you with), then you need to extract those messages and pass them to git commit:
git reset --soft HEAD~3 &&
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment