将先前的提交分成多个提交 [英] Break a previous commit into multiple commits

查看:110
本文介绍了将先前的提交分成多个提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有创建分支并在新分支上做了一些时髦的工作,在将其提交到本地存储库之后,是否可以将单个提交分成几个不同的提交?

Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it's been committed to the local repository?

推荐答案

git rebase -i 会做到这一点。

git rebase -i will do it.

首先,从一个干净的工作目录开始: git status 应该不显示正在进行的修改,删除或添加。

First, start with a clean working directory: git status should show no pending modifications, deletions, or additions.

要拆分最近的提交, / p>

To split apart your most recent commit, first:

$ git reset HEAD~

现在以通常的方式单独提交这些作品,并根据需要生成尽可能多的提交。

Now commit the pieces individually in the usual way, producing as many commits as you need.

如果它在树的后面,那么

If it was farther back in the tree, then

$ git rebase -i HEAD~3

其中 3 是多少次提交。

它更远了在树中,比你想要计算的,那么

If it was farther back in the tree than you want to count, then

$ git rebase -i 123abcd~

其中 123abcd 是要分离的提交的SHA1。

where 123abcd is the SHA1 of the commit you want to split up.

当你获得分配编辑屏幕时,找到你想要分离的提交。在该行的开头,用 edit e pick 简称)。保存缓冲区并退出。现在,Rebase将在您要编辑的提交之后停止。然后:

When you get the rebase edit screen, find the commit you want to break apart. At the beginning of that line, replace pick with edit (e for short). Save the buffer and exit. Rebase will now stop just after the commit you want to edit. Then:

$ git reset HEAD~

以通常的方式单独提交这些部分,根据需要生成尽可能多的提交,然后

Commit the pieces individually in the usual way, producing as many commits as you need, then

$ git rebase --continue

这篇关于将先前的提交分成多个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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