-
Notifications
You must be signed in to change notification settings - Fork 2
Git Squash
This is an awesome feature of rebase
that can be used in the interactive
mode. To squash the last n commits into one, run the following command:
git rebase -i HEAD~n
That will open up a text-editor with something similar to the following:
pick commit_1
pick commit_2
pick commit_3
...
pick commit_n
# Bunch of comments
Leave the first commit alone, and change the rest of the pick
s to squash
. Save and exit the editor.
So if you wanted to squash the last three commits, you'll first run git rebase -i HEAD~3
and then you'll want to edit your commits to look something like this:
pick dd661ba Commit 1
squash 71f5fee Commit 2
squash f4b4bf1 Commit 3
If you've already pushed to a remote before squashing your commits, you'll have to push to the remote again, with the -f
flag, otherwise git will throw an error at you.
It is strongly suggested that you read the information in the opened file as there are many things you can do.
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links