Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在StGit中拆分补丁?_Git - Fatal编程技术网

如何在StGit中拆分补丁?

如何在StGit中拆分补丁?,git,Git,在我决定将代码转换为实际提交之前,我正在使用补丁来管理代码。(旁注:是的,我知道,StGit补丁实际上只是在幕后提交) 然后,我在一个StGit补丁中添加了大量代码,但现在我想将其拆分为更小的补丁(稍后再进行更小的提交)。我该怎么做 $ vim foobar.ext Then I modify both functionA and functionB inside this file. This might require changes in other files as well. $ st

在我决定将代码转换为实际提交之前,我正在使用补丁来管理代码。(旁注:是的,我知道,StGit补丁实际上只是在幕后提交)

然后,我在一个StGit补丁中添加了大量代码,但现在我想将其拆分为更小的补丁(稍后再进行更小的提交)。我该怎么做

$ vim foobar.ext
Then I modify both functionA and functionB inside this file.
This might require changes in other files as well.
$ stg new large-patch
$ stg refresh
$ stg series
> large-patch

$ [insert here the answer to this question]

$ stg series
+ functionA-changes
> functionB-changes
$
到目前为止,我的解决方案是:

$ stg pop
Popped large-patch
No patch applied

$ stg show large-patch | patch -p1

$ git add -p
Here I interactively select which portions are going to be staged.

$ stg new functionA-changes
$ stg refresh --index

$ stg new functionB-changes
$ stg refresh

$ stg push
Pushing patch "large-patch" ... done (empty)
Now at patch "large-patch"

$ stg delete large-patch
Deleted large-patch (empty)
Now at patch "functionB-changes"
还有一种替代方法:

$ stg pop
Popped large-patch
No patch applied

$ stg show large-patch > foobar.patch
$ vim foobar.patch
Manually edit the patch
$ patch -p1 < foobar.patch
Now the files only have the changes from functionA.

$ stg new functionA-changes
$ stg refresh

$ stg rename large-patch functionB-changes
$ stg push
Pushing patch "functionB-chages" ... done
Now at patch "functionB-chages"
$stg pop
弹出大补丁
没有应用补丁
$stg显示大补丁>foobar.patch
$vim foobar.patch
手动编辑修补程序
$patch-p1
它可以工作,但仍然有点麻烦。我不知道是否有更好的解决办法。

有几种方法可以做到这一点。您可以选择在较小的和平中破坏补丁本身,或者从底部或顶部拾取部分补丁

选项1:拆分修补程序本身:

$stg删除大补丁--溢出
###对于0..N-1中的每个补丁i:
$stg新子补丁-$i
$git add-p。
$stg刷新--索引
选项2:从底部拾取:

$stg pop大补丁
###对于0..N-1中的每个补丁i:
$stg新子补丁-$i
$git checkout-p$(stg id大路径)
$stg刷新
$stg推送大补丁
选项3:从顶部拾取:

$stg刷新
$git重置头~1-p
$stg刷新-i
$stg全新顶级补丁
$stg刷新

第三个选项(从顶部开始)非常方便,但要复杂得多。您将以相反的方向选择更改。完成git reset后,索引中的更改将从修补程序中还原这些更改,而工作树中的更改将还原还原的更改,从而使用这些更改有效地创建一个新修补程序。

请记住一个命令以确保修补程序重新排列安全:
std push--set tree
。它推送下一个补丁,但避免合并。相反,它保留与修补程序关联的原始文件树。换句话说,即使编辑单个面片,也会保留面片的叠加

要拆分修补程序,请使用
stg pick--unapplied
复制原始修补程序。编辑原始修补程序后,复制的修补程序将自动拾取从原始修补程序中删除的更改

整个过程是这样的

# Make sure the patch to be split is on top

# Copy the current patch
stg pick --unapplied $(stg top)

# Make the first patch: remove hunks that go to the
# second patch, edit the description
stg edit --diff

# Some changes may be on the finer level than hunks, so let's
# do the fine tuning, test the patch, and make sure to run
# this after editing:
stg refresh

# Done with the first patch, now we go to the second patch,
# --set-tree does all the magic
stg push --set-tree

# All that's left is to edit the description of the second patch
stg edit --diff

这个讨论(和解决方案)看起来很相似:stg delete--spill将补丁内容保留在索引中。所以我想你在stg删除后错过了git重置。这很好,谢谢。如果能让上游文档包含这个例子,那就太好了。当我回到这里时,我只希望我能再投票给它一些!