I have git repository A and git repository B, and I would like to apply some of the patches from repo A to repo B by using stgit.
So far, my understanding is that I take these steps:
$ stg clone smthA.git repoA
$ cd repoA
$ stgit uncommit --number=100
$ stgit export
$ cd ../../repoBdir
$ stgit import ../../repoA/patchdir/patch_name_1
Can anyone confirm me this is correct procedure? Am I missing something?
How do I resolve error with "Trying to uncommit .... which does not have exactly one parent" that comes "$ stgit uncommit" in come cases?
Any advice or lesson learned here from people who have done this?
The steps you’ve outlined are basically correct. The
--diroption can be useful if you need to direct the output to, say, a shared drive. The--series(-s) option is helpful if you want to import the whole patch set. I use this a lot at work to initialize an stg git working copy on a new machine:If you don’t want to import every patch, you can specify them individually as you did in your example.
Another common need is to synchronize patches in multiple working copies (possibly on different machines).
stg syncis the command to use in this case:As far as the error about trying to uncommit a revision that has more than one parent: you basically can’t do this. From the stg-uncommit(1) man page:
This makes sense. If the history is not linear, StGit has no way of knowing which parent’s commits it should use. Depending on your needs, a possible workaround might be to create a temporary branch from one of the parents and cherry-pick the commits you need off of the other parent. This will create a linear history that you can then run
stg uncommiton to create a patch series. This might be okay if you’re just trying to generate a patch set that will apply cleanly to some particular source tree snapshot. However, you’re quite likely to run into trouble with this approach if you’re doing anything more complex than that. (It’s a hard problem; see this question for more perspective.)