views:

712

answers:

5

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?

+2  A: 

I read something about using grafts but never investigated it much.

Anyway, you can squash those last 2 commits manually with something like this:

git reset HEAD~1
git add -A
git commit --amend
Martinho Fernandes
+3  A: 

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
Pat Notz
+1  A: 

First, squash all your commits into a single commit using git rebase --interactive. Now you're left with two commits to squash. To do so, read any of

Frerich Raabe
A: 

The easiest way is to use the 'plumbing' command update-ref to delete the current branch.

You can't use git branch -D as it has a safety valve to stop you deleting the current branch.

This puts you back into the 'initial commit' state where you can start with a fresh initial commit.

git update-ref -d refs/heads/master
git commit -m "New initial commit"
Charles Bailey
+1  A: 

'echo "message" | git commit-tree HEAD^{tree}' will create an orphant commit with the tree of HEAD, and output it's name (SHA-1) on stdout. Then just reset your branch there.

kusma