Git 将初始提交拆分为 2

标签 git

<分区>

我的仓库有一个分支和许多不同的提交。初始提交包含一些代码。我想创建当前分支的 pull 请求,但要创建较早版本然后是初始提交,以便我可以查看已添加的整个相关代码。如何将一个提交拆分为 2 个?

最佳答案

您可以按照 this answer 中描述的过程进行操作至 "How to break a previous commit into multiple commits"除了您需要添加 --root 开关之外,因为您想要修改分支中的第一个提交。

来自 the documentation :

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

例如,假设你想修改 master 中的初始提交,你会说:

git checkout master
git rebase -i --root

关于Git 将初始提交拆分为 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41375681/

相关文章:

git - 如果我将一个文件添加到我的 git 存储库,然后在 gitignore 中添加一个表明该文件被忽略的模式,会发生什么

git - 如何将多个电子邮件地址链接到 Azure DevOps 中的一个用户?

git - 在 git 中,如何找到创建分支的修订版本?

git log 每个文件的提交计数

git - 为什么我的 git 不能通过 gitolite 使用 git-daemon 推送到我的服务器

git - 致命的 : Not a git repository: git status works. 但是 git 添加。没有

git - 如何在不提交的情况下将本地服务器上的更改与远程服务器上的更改同步?

git - 如何重用git中的分支?

Git 在从其他分支 pull 时要求提交消息

提交消息中的 Git 魔术关键字(签名人、合着者、修复等)