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.

20
  • 79
    <after-this-commit> is commit X+1 i.e. parent of the oldest commit you want to squash.
    – joozek
    Commented Nov 4, 2014 at 12:04
  • 28
    If you've already pushed the commits, you will need to push -f to forcibly move the remote branch to your new commit. This will upset anyone who was working on top of the old commits, though.
    – interfect
    Commented Dec 8, 2014 at 18:31
  • 89
    The difference between this rebase -i approach and reset --soft is, rebase -iallows me to retain the commit author, while reset --soft allows me to recommit. Sometimes i need to squash commits of pull requests yet maintaining the author information. Sometimes i need to reset soft on my own commits. Upvotes to both great answers anyways.
    – zionyx
    Commented Sep 15, 2015 at 9:31
  • 6
    I always end up screwing up the rebase for some reason, reset --soft seems more intuitive for most purposes.
    – yoyodunno
    Commented Jan 14, 2016 at 20:33
  • 61
    Use git rebase -i <after-this-commit> and replace "pick" on the second and subsequent commits with "squash" or "fixup", as described in the manual. uhhhh... wut?
    – Cheeso
    Commented Jul 27, 2016 at 3:18