## within current branch, squashes all commits that are ahead of master down into one | |
## useful if you merged with upstream in the middle of your commits (rebase could get very ugly if this is the case) | |
## commit any working changes on branch "mybranchname", then... | |
git checkout master | |
git checkout -b mybranchname_temp | |
git merge --squash mybranchname | |
git commit -am "Message describing all squashed commits" | |
git branch -m mybranchname mybranchname_unsquashed | |
git branch -m mybranchname | |
## optional, not recommended if you want to keep the unsquashed history around for a bit longer | |
git branch -D mybranchname_unsquashed | |
## if squashing already-pushed commits... | |
git push --force |
This comment has been minimized.
This comment has been minimized.
I used for three years. Scott! you are the best! |
This comment has been minimized.
This comment has been minimized.
Thank you, this is a masterpiece of gitmanship :squirrel: |
This comment has been minimized.
This comment has been minimized.
Another way, you can rebase on the parent of your first commit which is the pointer where your branch diverged.
|
This comment has been minimized.
This comment has been minimized.
lol.. I actually had to get some conflicts with rebase with master.. But above steps effectively got me the same thing as below could do:
Anyways, this is good enough. |
This comment has been minimized.
This comment has been minimized.
cheers bro, swish swish swish...another one bites the dust |
This comment has been minimized.
This comment has been minimized.
I frequently consult this GIST as I can never remember how to do this, and wish it were a single command in git. Thank you so much for saving me from rebase hell. |
This comment has been minimized.
This comment has been minimized.
Cheers again bro! |
This comment has been minimized.
This comment has been minimized.
Thanks a lot !! You saved my time :) |
This comment has been minimized.
This comment has been minimized.
Once again this has served me well...thanks! |
This comment has been minimized.
This comment has been minimized.
Fair play, this has once again pulled me from the darkness |
This comment has been minimized.
This comment has been minimized.
Nice one m8! |
This comment has been minimized.
This comment has been minimized.
Brilliant, thanks for this |
This comment has been minimized.
This comment has been minimized.
cool |
This comment has been minimized.
This comment has been minimized.
Note that you might face the issue of setting tracking information as well (connecting your new squashed branch to your remote one). To handle this you will need to do: |
This comment has been minimized.
thank you for saving me from rebase hell👍 ➕