gitrebasegit-rebasegit-rewrite-historygit-squash

How to squash all git commits into one?


How do you squash your entire repository down to the first commit?

I can rebase to the first commit, but that would leave me with 2 commits. Is there a way to reference the commit before the first one?


Solution

  • Perhaps the easiest way is to just create a new repository with current state of the working copy. If you want to keep all the commit messages you could first do git log > original.log and then edit that for your initial commit message in the new repository:

    rm -rf .git
    git init
    git add .
    git commit
    

    or

    git log > original.log
    # edit original.log as desired
    rm -rf .git
    git init
    git add .
    git commit -F original.log