How To Squash Commits Locally

Search for a command to run...

No comments yet. Be the first to comment.
The best talent comes from referrals. So how do you convince people to share their referrals? You reward them with cash. Problem now, how do you avoid people sharing “referrals” mindlessly? You vet them. Reach out to your network, ask if they know s...
If you've faced this situation before, you might want to learn this. You're working on feature A at your work and suddenly you got a ping on Slack. "Please fix this bug, it's causing a critical bug in production that needs fixing ASAP!!!" You git st...
Before we start, please read the QRTs from both Edd and Mu'azh. They both have presented a great point about luck Keep working and grinding so that you're prepared to take advantage of luck when it comes. Me however, I'm here to share about how t...
Open the PDF file in Chromium-based browsers Print as PDF https://twitter.com/afrieirham_/status/1681196950715088897
If you're like me, you've probably heard this advice a lot, especially in the tech industry. "Go do more interviews, even especially if you're not actively looking." And they're right, here's why. You have higher leverage in negotiation when you're n...
If you're like me, you're probably familiar with "squash and merge" when merging pull requests on GitHub.
If you're also like me, you're now trying to figure out how to do this seemingly simple "squash and merge" thingy locally for some reason.
Whether you've been asked to do it because that's how your team has done it (read: my team) or you're curious how to do it just to learn – you've come to the right place.
The main idea of squashing your commits is you need to reset or undo your commits until the very last one you want to squash. Then just git commit again.
Where, N = number of commits you want to squash
For example, if you have 3 commits that you want to squash, you can simply git reset --soft HEAD~3
IMPORTANT: make sure it's a *soft* reset by using the --soft flag.
Otherwise, you will lose all of your progress. We don't want that.
This is pretty straightforward, just git commit -m ...
And that's it, it's pretty simple when you know now but it was quite confusing if you're used to the 1-click squash and merge button on GitHub.
At least that was the case for me. 🥲