The rebase -i
command mentioned by @rakwaht is indeed a useful tool for rewriting history (typically for rewriting the local history composed of a small number of commits that have not yet been pushed), but I believe this is not the best tool for the OP's use case.
A more practical solution would be to define a GraftPoint containing the SHA1 of the first commit you want in your history, and rely on git filter-branch to make the root commit change permanent (this step is a destructive operation, so make sure you have a backup of your repo beforehand)
This solution has already been proposed in this question on SO for another, similar use case.
To sum up, you could do (assuming you have a backup of your repo folder):
git checkout feature
# to checkout the branch of the new project
git log --graph --decorate --pretty=oneline
# to find the first commit to be kept (adding initial files in the new project)
echo 1234567890123456789012345678901234567890 > .git/info/grafts
# to define a GraftPoint with the appropriate SHA1
gitk
# to preview the impact of this GraftPoint
git filter-branch --prune-empty -- HEAD
# to rewrite the history of the current branch, as per the GraftPoint
# --prune-empty is optional and allows one to skip commits with empty content
rm .git/info/grafts
# to remove the GraftPoint and thus restore the other branches
gitk --all
# to inspect all branches
# --> note that the SHA1 of all commits in the feature branch have changed,
# so the new history is incompatible with the old one (w.r.t. merges, etc.)
In case you want the feature
branch to be the only branch in your repo and forget everything else, you might want to delete the other branches, then purge the reflog and the corresponding commits by running these commands (beware: destructive operation):
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now --aggressive
cf. this part of git-filter-branch's documentation, as well as the web site of the BFG repo cleaner (which is an alternative of git filter-branch
that enjoys better performance and may be useful in other use cases to forcibly rewrite Git history)
Hoping this helps