Reputation: 4462
I have started a project and already have some commits. I would like to change my approach, and commit everything on a clean slate. Is it possible to commit a work tree as an unconnected first commit directly, or do I really need to use a temporary remote for that?
Basically how I know I can do:
mkdir BOO
cd BOO
git init
... # create the first and maybe more commits...
cd ..
git remote add boo BOO
git fetch boo
git checkout -b boo/master new-master
git remote delete boo
rm -rf BOO/
Do I really need to use a temporary remote definition like above, or is there a way to directly create an unconnected starting commit?
(If it is not evident from the question, I would like to keep the original main branch still intact, at least for a while, for verification purposes (git diff
) and for cherry-picking.)
Upvotes: 1
Views: 411
Reputation: 4462
Another obvious approach is to do
git checkout -b master-again
git rebase -i --root
(it does not actually matter which branch you are in the beginning), and delete every commit in the opened editor, except the initial commit, which would be marked as edit
and then replaced with the initial commit of the changed approach when the actual interactive rebase starts.
I think it would be possible to automate this to a single command by setting GIT_EDITOR
to point to a suitable script.
I am looking for something even more straightforward, though, and something already existing.
Upvotes: 1