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?
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?
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
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
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
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"
'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.