Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting the first commit in git [duplicate]

Tags:

git

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?

like image 878
ZelluX Avatar asked Sep 12 '10 16:09

ZelluX


People also ask

How do you break a rebase?

To interrupt the rebase (just like an " edit " command would do, but without cherry-picking any commit first), use the " break " command.

What is git reset -- soft?

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.


1 Answers

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.

like image 181
CB Bailey Avatar answered Sep 16 '22 18:09

CB Bailey