imz*_*hev 5 patch rebase darcs
在darcs中,如果我想将其他补丁所依赖的补丁重新排序到顶部(或直接扔掉)(即更改同一文件)怎么办?
在 git 中,我只需执行 agit rebase -i <UNTOUCHED-REVISION>并重新排序或丢弃一些更改;然后 git 会以一种愚蠢的方式尝试将旧的更改一一应用到树的新变体,并要求我解决出现的冲突。
在darcs中,我认为没有办法强制它忽略补丁之间的依赖关系。如果我obliterate或suspend(或unrecord)其他补丁依赖的补丁,darcs 会拒绝这样做。(因为它想要以聪明的方式行事。)
我有以下计划来做到这一点:
以下是有关这一切如何进行的一些注释。
如果依赖于您想要重新排序的补丁的补丁中有一个“最小”补丁(根据依赖关系图),那么您只需发出命令即可挂起它(之后将不再有“活动”补丁) “ 补丁取决于重新排序的补丁):
darcs suspend -h <MINIMAL-DEPENDENT-HASH>
Run Code Online (Sandbox Code Playgroud)
(并确认所有其他依赖补丁的暂停)。
当然,如果有几个最小依赖补丁,则必须暂停每个补丁(每个子图都会被要求暂停)。
首先,我看看我将要进行的更改:
darcs diff -h 61fbb4aeac9e69cf30d232eda274c18194d7a8d9 --diff-command='emacs -f ediff-directories-with-ancestor-command %1 %2'
Run Code Online (Sandbox Code Playgroud)
(这一变化在逻辑上很简单,但diff以一种复杂的方式表现出来,所以,在这里,我通过为此目的编写的一个特殊函数启动了 Emacs 的 ediff。)
我看到更改包括一些清理和添加新功能。因此,现在的计划是对其进行拆分:取消记录补丁,并记录两个补丁。
darcs unrec -h 61fbb4aeac9e69cf30d232eda274c18194d7a8d9
Run Code Online (Sandbox Code Playgroud)
现在,我也可以使用 ediff 查看和(也许可以工作)更改。
darcs diff --diff-command='emacs -f ediff-directories-with-ancestor-command %1 %2'
Run Code Online (Sandbox Code Playgroud)
首先,我记录清理补丁(仅选择和编辑相关的块)。然后,添加动作:
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)'
Run Code Online (Sandbox Code Playgroud)
人们可以使用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 $
Run Code Online (Sandbox Code Playgroud)
那么,让我们制作一个副本(并检查我们是否可以从中提取):
~/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 $
Run Code Online (Sandbox Code Playgroud)
好的,很好,所以我们稍后将从该存储库中提取。
丢弃不需要的(或重新排序的)补丁:
darcs obliterate
Run Code Online (Sandbox Code Playgroud)
此时最好制作存储库的备份副本,因为在取消挂起和解决冲突期间您可能会搞砸一些事情。
取消挂起应该在其之前的补丁。(不幸的是,. 中不支持外部合并工具unsuspend。)最好将它们一一取消挂起,因为您必须解决每个工具引起的冲突并修改补丁:
darcs rebase unsuspend
# resolve conflicts
darcs amend
# repeat for the remaining patches you want to have
Run Code Online (Sandbox Code Playgroud)
darcs pull ../../language-c_printAST
# resolve conflicts
darcs amend
Run Code Online (Sandbox Code Playgroud)
(再次强调,最好一项一项地进行。)
darcs rebase unsuspend
# resolve conflicts
darcs amend
# repeat for the remaining patches you want to have
Run Code Online (Sandbox Code Playgroud)
(由于某种原因,在第一次尝试时,我在最后一个未暂停的补丁中丢失了一个块。但我在备份副本的副本中重复了所有内容,并在那里达到了希望的最终状态。)