0

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?

Bojan Milankovic
  • 847
  • 3
  • 11
  • 23

1 Answers1

3

The steps you've outlined are basically correct. The --dir option 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:

# On Machine A (existing StGit repo with all patches applied)
$ stg export --dir /y/projects/ttc_dev_stg_patches/master
Checking for changes in the working directory ... done

# On Machine B ('pristine' StGit repo with no patches)
$ stg series [<-- should have no output!]
$ stg import -s /y/projects/ttc_dev_stg_patches/master/series
Checking for changes in the working directory ... done
Importing patch "remove-stl-at" ...
  Invoking the editor: "vim .stgitmsg.txt" ... done
done
Importing patch "wldap32-fix" ...
  Invoking the editor: "vim .stgitmsg.txt" ... done
done
Importing patch "cmake-fixes" ...
  Invoking the editor: "vim .stgitmsg.txt" ... done
done
Now at patch "cmake-fixes"

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 sync is the command to use in this case:

# On Machine B (existing StGit repo)
$ stg series
+ remove-stl-at
+ wldap32-fix
> cmake-fixes
$ stg sync --all -s /y/projects/ttc_dev_stg_patches/master/series
Checking for changes in the working directory ... done
Popping patches "cmake-fixes" - "wldap32-fix" ... done
Synchronising "remove-stl-at" ... done (updated)
Fast-forwarded patch "wldap32-fix"
Synchronising "wldap32-fix" ... done
Fast-forwarded patch "cmake-fixes"
Synchronising "cmake-fixes" ... done (updated)

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:

Only commits with exactly one parent can be uncommitted; in other words, you can't uncommit a merge.

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 uncommit on 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.)

Community
  • 1
  • 1
evadeflow
  • 4,704
  • 38
  • 51