Squash all Commits into a Single Commit

Sometimes it makes sense to start over in Git's history while maintaining the current state of your code.

Git has many built-in tools to rewrite history. But, sometimes, you just want to take where you are in history, squash everything into a single commit, and move forward from there.

While you could go through the interactive rebase methods, it's easier to just wipe out git and start over. You do this by removing the .git directory and reinitializing the repo.

Here are the commands to run from inside your repository.

$ rm -rf .git
$ git init
$ git add .
$ git commit -am "You restarting commit message"

CAUTION: This method will remove the entire git history. This means branches, tags, etc. are all gone. If you're worried about the effects this may have, you can do a test run by renaming your .git directory first, and not deleting until you reinitialized repository looks good. Of course, ideally you've already pushed this repo to a remote location, so anything you mess up locally can be undone.

Let's Connect

Keep Reading

Learn Git in an Hour

Although I'm no expert, I've outlined the things I think you need to know to get started using Git.

Jul 04, 2013

Git Merge: Accept All Changes

Have you encountered a large merge when you know you are going to accept all current or incoming changes? There's a way to achieve without stepping through each file.

Sep 17, 2020

Backup Gitlab Data and Repositories to Amazon S3

Make sure you don't lose all that precious GitLab data by backing regularly and syncing with an Amazon S3 bucket.

Dec 11, 2014