在git中拆分第一次提交 [英] Splitting the first commit in git

查看:77
本文介绍了在git中拆分第一次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在git存储库中拆分第一个提交,但是我不能使用rebase来做到这一点,因为需要父节点.我发现在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?

推荐答案

您可以按照与链接到的问题完全相同的过程进行操作,但是在检查了root提交之后,您可以使用 git commit--amend 修改原始提交,然后 git commit 进行其他提交,然后继续执行rebase命令.

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.

根据您想要分割提交的方式,可以使用 git rm --cached 删除要在初始 git commit --amend之前的第二次提交中添加的文件.并编辑要更改外观的任何文件,然后再对这些文件调用 git add ,再调用 git commit --amend .

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.

在调用 git commit --amend 之后,要确保完全提交原始root提交的状态,可以调用:

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> -- .

在调用 git commit 进行拆分根提交的第二次提交之前.

before calling git commit to make the second commit of the split root commit.

这篇关于在git中拆分第一次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆