Last active
May 11, 2020 19:05
-
-
Save luiarthur/1c8df5de34e40f9f397d5b4ba0dd9331 to your computer and use it in GitHub Desktop.
git rebase (squashing several commits)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to squash several commits into one big commit | |
See this also: https://www.internalpointers.com/post/squash-commits-into-one-git | |
1. Inspect the previous commits to see where you want to place the last commit | |
``` | |
git log --oneline | |
``` | |
2. Rebase | |
``` | |
git rebase -i <commit-hash-of-last-working-commit> | |
``` | |
3. An editor will now be shown. Change `pick` to `squash` (or `s` for brevity) for all but the most recent commit. | |
(There's no need to change the commit messages at this point.) For example: | |
``` | |
pick d94e78 Prepare the workbench for feature Z --- older commit | |
s 4e9baa Cool implementation | |
s afb581 Fix this and that | |
s 643d0e Code cleanup | |
s 87871a I'm ready! | |
s 0c3317 Whoops, not yet... | |
s 871adf OK, feature Z is fully implemented --- newer commit | |
``` | |
4. Finally, another editor will appear, and you can change the commit message for the final commit. | |
5. Your branch should be different from upstream now. So, do a | |
``` | |
git push -f | |
``` | |
to merge. | |
6. All Done. Merge this branch into master. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment