So I\'m migrating from svn (code.google.com) to git(github).
I\'ve imported my project from the svn repo, and it imported all the commit history along way. I\'m not real
Find the hash of the commit that you want to start squashing from say abcd12
and then rebase against that hash specifically.
git rebase -i abcd12
You are using master
to rebase against, which performs the rebase against the tip of the master branch.
git rebase -i --root
will start an interactive rebase of all commits from the beginning.
From there, you can squash all commits into one and/or perform other edits.
Jefromi's answer will work, but if you want to keep your existing repo configuration, or even leave around the commits just in case, you could do the following:
git checkout master
git branch backup
optionally leave another branch here in case you want to keep your history.
git reset --soft $SHA_OF_INIT_COMMIT
this will update what HEAD is pointing to but leave your index and working directory in their current state. You can get the SHA with git log --pretty=format:%h --reverse | head -n 1
, and make this one step with git reset --soft $(git log --pretty=format:%h --reverse | head -n 1)
git commit --amend
change your initial commit to point to the current state of your repo.
You could rebase and squash everything if you wanted to (except the initial commit) but why bother? Simply delete your .git directory, run git init
to recreate it, git add
everything, and git commit
to make a new initial commit.
If you'd like to reduce all your history to a single "Initial import" commit, simply remove .git
directory and create a new local repository (keeping a backup of the old one). git init . && git add . && git commit -m "Initial import"
.
Such new repository won't have a common ancestor with the one you've pushed to GitHub, so you'll have to git push --force
your newly created repository.