I want to split the first commit in my git repository, but I cannot use rebase to do this because a parent node is required. I found Edit the root commit in Git? useful for modifying the first commit, but not splitting it. How can I split it?
To interrupt the rebase (just like an " edit " command would do, but without cherry-picking any commit first), use the " break " command.
git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory. Only use this if you know what you're doing.
You can just follow exactly the same process in the question you've linked to, but after checking out the root commit you can use git commit --amend
to modify the original commit and then git commit
to make an additional commit before continuing the with the rebase command.
Depending on how you want to split the commit you can use git rm --cached
to remove files that you want to add at the second commit before the initial git commit --amend
and edit any files that you want to look different before calling git add
on those files, again before you call git commit --amend
.
After calling git commit --amend
, to make sure that you commit exactly the state of the original root commit you can call:
git checkout <sha1-of-original-root> -- .
before calling git commit
to make the second commit of the split root commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With