我有以下计划来做到这一点:
- 暂停依赖补丁(那些依赖于我想要重新排序或丢弃的补丁的补丁)。
- 以某种方式取消记录补丁以重新排序并将其保存在其他地方(可能在另一个“darcs 分支”中,即存储库的副本)并将更改恢复到工作目录,以便工作目录是干净的。
- 之后,将挂起的补丁解挂到我想要插入重新排序的补丁的状态。(解决所有出现的冲突。)
- 应用保存的补丁(也许,通过从保存的“分支”中提取,即我在步骤 2 中保存的 darcs 存储库的副本)。
- 取消暂停所有剩余的补丁。(解决所有出现的冲突。)
这里有一些关于这一切是如何进行的说明。
1.暂停依赖补丁
如果在依赖于您要重新排序的补丁的补丁中,有一个“最小”的(根据依赖关系图),那么您只需发出命令将其挂起(之后将没有“活动" 取决于重新排序的补丁的补丁):
darcs suspend -h <MINIMAL-DEPENDENT-HASH>
(并确认所有其他相关补丁的暂停)。
当然,如果有几个最小的依赖补丁,你必须暂停每个(每个子图都会被要求暂停)。
2.保存并还原不需要的更改
准备
首先,我看看我将要进行的更改:
darcs diff -h 61fbb4aeac9e69cf30d232eda274c18194d7a8d9 --diff-command='emacs -f ediff-directories-with-ancestor-command %1 %2'
(这个变化在逻辑上很简单,但是diff
以一种复杂的方式显示出来,所以,在这里,我通过为此目的编写的一个特殊函数启动了 Emacs 的 ediff。)
我看到更改包括一些清理和添加新功能。因此,现在计划将其拆分:取消录制补丁,并改为录制两个补丁。
darcs unrec -h 61fbb4aeac9e69cf30d232eda274c18194d7a8d9
现在,我也可以使用 ediff 查看和(也许可以工作)更改。
darcs diff --diff-command='emacs -f ediff-directories-with-ancestor-command %1 %2'
首先,我记录清理补丁(仅选择和编辑相关的大块)。然后,添加的操作:
darcs rec -m 'examples/Process.hs: code cleanup (present as a sequence of actions and error handling)'
darcs rec -m 'examples/Process.hs: print the C program (from the AST) after the check (as gcc -E does)'
另存为补丁(变体)
可以使用darcs obliterate -o
或-O
保存已删除的更改,然后使用darcs apply
(根据该建议)将其恢复。
但我采取了不同的方式:
另存为分支(变体)
克隆不适用于带有暂停补丁的回购:
~/TOOLS/prog/language-c $ darcs clone . ../language-c_printAST
darcs failed: Can't clone a repository with a rebase in progress
~/TOOLS/prog/language-c $
所以,让我们制作一个副本(并检查我们是否可以从中提取):
~/TOOLS/prog/language-c $ cp -a ../language-c ../language-c_printAST
~/TOOLS/prog/language-c $ darcs pull ../language-c_printAST
darcs failed: Incompatibility with repository /home/imz/TOOLS/prog/language-c_printAST:
Cannot transfer patches from a repository where a rebase is in progress
~/TOOLS/prog/language-c $ cd ../language-c_printAST/
~/TOOLS/prog/language-c_printAST $ darcs rebase obliterate
<...>
Really obliterate all undecided patches? y
Rebase finished!
~/TOOLS/prog/language-c_printAST $ cd ../language-c
~/TOOLS/prog/language-c $ darcs pull ../language-c_printAST
HINT: if you want to change the default remote repository to
/home/imz/TOOLS/prog/language-c_printAST,
quit now and issue the same command with the --set-default flag.
No remote patches to pull in!
~/TOOLS/prog/language-c $
好的,好的,所以我们稍后会从那个 repo 中提取。
还原更改
丢弃不需要的(或重新排序的)补丁:
darcs obliterate
3.取消挂起应该在它之前的补丁
此时制作 repo 的备份副本是个好主意,因为您可能会在取消暂停和解决冲突期间搞砸一些事情。
取消挂起应该在它之前的补丁。(不幸的是,外部合并工具不支持unsuspend
。)最好将它们一一解除,因为您必须解决每个引起的冲突并修改补丁:
darcs rebase unsuspend
# resolve conflicts
darcs amend
# repeat for the remaining patches you want to have
4.应用保存的补丁
darcs pull ../../language-c_printAST
# resolve conflicts
darcs amend
5. 取消暂停所有剩余的补丁。
(同样,最好一个一个地做这个。)
darcs rebase unsuspend
# resolve conflicts
darcs amend
# repeat for the remaining patches you want to have
(出于某种原因,在第一次尝试时,我在最后一个未挂起的补丁中丢失了一个大块。但我在备份副本的副本中重复了所有内容,并且在那里我达到了希望的最终状态。)