Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a patch in StGit?

Tags:

git

I'm using StGit to manage my code using patches before I decide it's time to convert it to actual commits. (sidenote: yes, I know, StGit patches are actually just commits under-the-hood)

Then I added large amount of code to a single StGit patch, but now I want to split it into smaller patches (and later to smaller commits). How can I do that?

$ 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
$
like image 422
Denilson Sá Maia Avatar asked Mar 28 '14 01:03

Denilson Sá Maia


People also ask

How do you split a patch?

In other words, the superposition of the patches is preserved even when individual patches are edited. For splitting a patch, copy the original patch using stg pick --unapplied . After the original patch is edited, the copied patch would automatically pick up the changes removed from the original patch.

What is StGit?

Stacked Git, StGit for short, is an application for managing Git commits as a stack of patches. With a patch stack workflow, multiple patches can be developed concurrently and efficiently, with each patch focused on a single concern, resulting in both a clean Git commit history and improved productivity.


1 Answers

There are several ways to do this. You can choose to break the patch itself in smaller peaces, or pick parts of it from the bottom or from the top.

Option 1: Split 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: Pick from its bottom:

$ 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: Pick from its top:

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

This third option (from the top) is very handy, but it is a lot more complicated. You will be picking your changes in the reverse direction. When you are done with git reset, your changes in the index will be reverting those changes from the patch, while the changes in the working tree will be reverting the reverted changes, effectively creating a new patch with those changes.

like image 181
Juliano Avatar answered Sep 22 '22 02:09

Juliano