开发者

Splitting the first commit in git [duplicate]

This question already has answers here: 开发者_StackOverflow社区 Edit the root commit in Git? (5 answers) Change first commit of project with Git? [duplicate] (4 answers) Closed 9 years ago.

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?


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.


You can use the --root option to tell rebase that you want to rewrite the root/first commit:

$ git rebase --interactive --root

Then the root commit will show up in the rebase TODO list, and you can select to edit it:

edit <root commit sha> <original message>
pick <other commit sha> <message>
...

This is the explanation of --root from the Git rebase docs:

Rebase all commits reachable from <branch>, instead of limiting them with an <upstream>. This allows you to rebase the root commit(s) on a branch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜