How to break a patch in StGit?

I use StGit to manage my code with patches before I take the time to convert it to actual commits. (sidenote: yes, I know, StGit patches actually just commit under the hood)

Then I added a large amount of code to one StGit patch, but now I want to break it into smaller patches (and then into smaller commits). How can i do this?

$ 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
$
+4
source share
3 answers

There are several ways to do this. You can break the patch in smaller sizes yourself or choose a part of it from the bottom or top.

Option 1: Divide the patch itself:

$ stg delete large-patch --spill

### for each patch i in 0..N-1:
$ stg new sub-patch-$i
$ git add -p .
$ stg refresh --index

Option 2: select from below:

$ stg pop large-patch

### for each patch i in 0..N-1:
$ stg new sub-patch-$i
$ git checkout -p $(stg id large-path)
$ stg refresh

$ stg push large-patch

Option 3: select from above:

$ stg refresh
$ git reset HEAD~1 -p
$ stg refresh -i
$ stg new new-top-patch
$ stg refresh

() , . . git reset, , , .

+5

:

$ 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"

, . , .

+1

I made a script stg-splitto split the current StGit patch. It launches stg edit --diffand allows the user to remove pieces that fall into a separate patch. You can also edit the added lines to undo some changes. The modified patch saves the name. Changes between the edited patch and the original patch will become the new patch. The user is then prompted to describe the new patch. Add-ons and deletions are supported. See https://gist.github.com/proski/70cee51018ab59ff1fe4f413650ec4a8

0
source

Source: https://habr.com/ru/post/1533834/


All Articles