DEV Community

Cover image for Git - Squash
kulsoomzahra for eduAlgo

Posted on

3 1

Git - Squash

Using git/github for your personal projects is pretty easy but when you're a part of an organisation or a large scale project with thousands of users you might get a tough time. One wrong move can cause mess or make the commit tree dirty or anything you don't want which in turn may fuel your Impostor Syndrome!
So hey, HANG ON! You can do it.

A Clean Commit Tree

Squashing your commits can help so here we go

  1. Switch to the branch where the commit tree is
    git checkout <branch name>

  2. Make sure everything on your local is pushed to the branch
    git add .
    git commit -m "Commit message"
    git push origin <branch name>

  3. Squash n previous commits
    (n is the no.of commits you want to squash)
    git rebase -i HEAD~3

Alt Text

Now, change pick to s or squash in the last 2 commits
Press
a) Ctrl + O to write out
b) Enter to save changes
c) Ctrl + X to exit

Now you can edit the final commit message .
Repeat a,b,c

Don't forget to PUSH your changes on to the branch
git push origin <branch name>

If this doesn't work force push your changes
git push origin <branch name> -f

You're Done! Now you have a clean commit tree.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (2)

Collapse
 
abhijit2505 profile image
Abhijit Tripathy

Amazing 🥳

Collapse
 
kulsoomzahra profile image
kulsoomzahra

Thanks :)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more