close
Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

How do I squash my last N commits together?

How do I squash my last N commits together into one commit?

Answer*

Draft saved
Draft discarded
Cancel
3
  • 9
    +1: that's fun and instructive, in that it's wasn't at all obvious to me that you can put anything more complex than the name of a program in the GIT_EDITOR environment variable. Commented Mar 4, 2011 at 21:04
  • You could simplify this using gawk. git -c core.editor="gawk -i inplace '{if(NR>1 && \$1==\"pick\"){\$1=\"squash\"} print \$0}'" rebase -i --autosquash HEAD~5. Commented Aug 30, 2020 at 8:56
  • I prefer this command with GIT_SEQUENCE_EDITOR, for I need autostash Commented Dec 25, 2021 at 23:02