这通常是交互式rebase期间我们将运行git rebase --continue的点,因为我们通常只想返回提交堆栈以编辑之前的提交。但这一次,我们想创建一个新的提交。所以我们将运行git commit -am 'two and a third'。现在我们编辑文件A并添加行two and two thirds。
git add .git commit -am 'two and two thirds'git rebase --continue
我们的提交有冲突,three,所以让我们解决它:
我们会改变
one<<<<<<< HEADtwo and a thirdtwo and two thirds=======twothree>>>>>>> bfb8e46... three
来
onetwo and a thirdtwo and two thirdsthree
git add .; git rebase --continue
现在我们的git log -p看起来像这样:
commit e59ca35bae8360439823d66d459238779e5b4892Author: Rose Perrone <roseperrone@fake.com>Date: Sun Jul 7 13:57:00 2013 -0700
three
diff --git a/A b/Aindex 5aef867..dd8fb63 100644--- a/A+++ b/A@@ -1,3 +1,4 @@onetwo and a thirdtwo and two thirds+three
commit 4a283ba9bf83ef664541b467acdd0bb4d770ab8eAuthor: Rose Perrone <roseperrone@fake.com>Date: Sun Jul 7 14:07:07 2013 -0700
two and two thirds
diff --git a/A b/Aindex 575010a..5aef867 100644--- a/A+++ b/A@@ -1,2 +1,3 @@onetwo and a third+two and two thirds
commit 704d323ca1bc7c45ed8b1714d924adcdc83dfa44Author: Rose Perrone <roseperrone@fake.com>Date: Sun Jul 7 14:06:40 2013 -0700
two and a third
diff --git a/A b/Aindex 5626abf..575010a 100644--- a/A+++ b/A@@ -1 +1,2 @@one+two and a third
commit 9aac58f3893488ec643fecab3c85f5a2f481586fAuthor: Rose Perrone <roseperrone@fake.com>Date: Sun Jul 7 13:56:40 2013 -0700
one
diff --git a/A b/Anew file mode 100644index 0000000..5626abf--- /dev/null+++ b/A@@ -0,0 +1 @@+one
$ git statusinteractive rebase in progress; onto be83b41Last commands done (3 commands done):pick 4847406 US135756: add debugging to the file download codee 65dfb6a US135756: write data and download from remote(see more in file .git/rebase-merge/done)...
# first rewind back (mind the dot,# though it can be any valid path,# for instance if you want to apply only a subset of the commit)git reset --hard <previous-commit> .
# apply the changesgit checkout <commit-you-want-to-split>
# we're almost there, but the changes are in the index at the moment,# hence one more step (exactly as git gently suggests):# (use "git reset HEAD <file>..." to unstage)git reset
在此之后,您将看到这个闪亮的Unstaged changes after reset:,并且您的repo处于您即将提交所有这些文件的状态。从现在开始,您可以像往常一样轻松地再次提交它。希望它有帮助。
将此编辑作为新的提交提交,类似于git add . ; git commit -m 'removal of things that should be changed later',因此您将在历史中拥有原始提交,并且您还将拥有另一个提交,其中包含您所做的更改,因此当前HEAD上的文件看起来像您希望它们在拆分后的第一次提交中。
000aaa Original commit000bbb removal of things that should be changed later
000aaa Original commit000bbb removal of things that should be changed later000ccc Revert "removal of things that should be changed later" (assuming you didn't edit commit message immediately)
现在,您可以使用git rebase -i将前两个提交压缩/修复为一个提交,如果您之前没有向其提供有意义的提交消息,则可以选择修改恢复提交。你应该留下
000ddd Original commit, but without some content that is changed later000eee Things that should be changed later