Skip to content

Instantly share code, notes, and snippets.

@siddhpant
Created October 1, 2020 14:30
Show Gist options
  • Save siddhpant/9f1097dcb3423a497caf49951d9c9205 to your computer and use it in GitHub Desktop.
Save siddhpant/9f1097dcb3423a497caf49951d9c9205 to your computer and use it in GitHub Desktop.
git squash alias
[alias]
squash = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"
@siddhpant
Copy link
Author

siddhpant commented Oct 1, 2020

From https://stackoverflow.com/a/21890252

Now to squash last X commits use git squash X.

For example, to squash the last 4 commits, use git squash 4.

Note that git squash 1 will also trigger reset due to it's working and the previous commit will be edited/overwritten with a new one, with a new hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment