1.8 KiB
title | date | permalink | tags | cta | snippet | ||
---|---|---|---|---|---|---|---|
Local merging and squashing | 2024-12-12 | daily/2024/12/12/local-squashing |
|
~ | If you want to squash all the commits on your Git branch locally without rebasing, there is a way! |
Because I do trunk-based development, I typically don't create branches in Git.
If I do, I usually want to keep the commit messages, but there are some situations where I want to squash everything into a single commit with a simple message.
Typically, I'd do this using a rebase command like git rebase -i main
and get an output like this, showing the commits:
pick d21fafc Remove encrypted disk configuration
pick ffc1296 Update mount location for media directories
pick 58f645e Add multigrep from TJ's video
pick bbd5052 Revert "Remove encrypted disk configuration"
pick 8280c49 Show more generations on boot
pick d3b0c48 Revert "Add encrypted media drive"
pick 8cdc6a5 Add paperless-ngx
pick 73d801d Add Nick Janetakis' `notes` script
pick 99b6e3b Set options for text files
I can change pick
to squash
or fixup
and decide what to do for each commit.
squash
combines the commit with the previous one, including the commit messages.
fixup
uses the previous commit message and discards the current one.
Once the file is saved, the rebase is performed and the actions are executed.
There is another way
If you don't want any of the commit messages, you can also use git merge --squash
.
This will automatically squash all the commits - ready for you to run git commit
and provide the final message.
There's no option to merge or combine the previous messages, though.
If you want to do that, you can still use the rebase approach.
If not, use git merge --squash
.