diff --git a/source/_daily_emails/2024-12-12.md b/source/_daily_emails/2024-12-12.md new file mode 100644 index 00000000..eec71624 --- /dev/null +++ b/source/_daily_emails/2024-12-12.md @@ -0,0 +1,51 @@ +--- +title: Local merging and squashing +date: 2024-12-12 +permalink: daily/2024/12/12/local-squashing +tags: + - software-development + - git +cta: ~ +snippet: | + 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][0], 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: + +```plain +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`. + +[0]: {{site.url}}/archive/2022/09/20/why-like-trunk-based-development