1 TopGit - A different patch queue manager
7 TopGit aims to make handling of large amount of interdependent topic
8 branches easier. In fact, it is designed especially for the case
9 when you maintain a queue of third-party patches on top of another
10 (perhaps Git-controlled) project and want to easily organize, maintain
11 and submit them - TopGit achieves that by keeping a separate topic
12 branch for each patch and providing few tools to maintain the branches.
23 Why not use something like StGIT or Guilt or rebase -i for maintaining
24 your patch queue? The advantage of these tools is their simplicity;
25 they work with patch _series_ and defer to the reflog facility for
26 version control of patches (reordering of patches is not
27 version-controlled at all). But there are several disadvantages -
28 for one, these tools (especially StGIT) do not actually fit well
29 with plain Git at all: it is basically impossible to take advantage
30 of the index effectively when using StGIT. But more importantly,
31 these tools horribly fail in the face of distributed environment.
33 TopGit has been designed around three main tenets:
35 (i) TopGit is as thin layer on top of Git as possible.
36 You still maintain your index and commit using Git, TopGit will
37 only automate few indispensable tasks.
39 (ii) TopGit is anxious about _keeping_ your history. It will
40 never rewrite your history and all metadata is also tracked by Git,
41 smoothly and non-obnoxiously. It is good to have a _single_ point
42 when the history is cleaned up, and that is at the point of inclusion
43 in the upstream project; locally, you can see how your patch has evolved
44 and easily return to older versions.
46 (iii) TopGit is specifically designed to work in distributed
47 environment. You can have several instances of TopGit-aware repositories
48 and smoothly keep them all up-to-date and transfer your changes between
51 As mentioned above, the main intended use-case for TopGit is tracking
52 third-party patches, where each patch is effectively a single topic
53 branch. In order to flexibly accommodate even complex scenarios when
54 you track many patches where many are independent but some depend
55 on others, TopGit ignores the ancient Quilt heritage of patch series
56 and instead allows the patches to freely form graphs (DAGs just like
57 Git history itself, only "one level higher"). For now, you have
58 to manually specify which patches does the current one depend
59 on, but TopGit might help you with that in the future in a darcs-like
62 A glossary plug: The union (i.e. merge) of patch dependencies is
63 called a _base_ of the patch (topic branch).
65 Of course, TopGit is perhaps not the right tool for you:
67 (i) TopGit is not complicated, but StGIT et al. are somewhat
68 simpler, conceptually. If you just want to make a linear purely-local
69 patch queue, deferring to StGIT instead might make more sense.
71 (ii) When using TopGit, your history can get a little hairy
72 over time, especially with all the merges rippling through. ;-)
78 ## Create and evolve a topic branch
79 $ tg create t/gitweb/pathinfo-action
80 tg: Automatically marking dependency on master
81 tg: Creating t/gitweb/pathinfo-action base from master...
87 ## Create another topic branch on top of the former one
88 $ tg create t/gitweb/nifty-links
89 tg: Automatically marking dependency on t/gitweb/pathinfo-action
90 tg: Creating t/gitweb/nifty-links base from t/gitweb/pathinfo-action...
94 ## Create another topic branch on top of master and submit
95 ## the resulting patch upstream
96 $ tg create t/revlist/author-fixed master
97 tg: Creating t/revlist/author-fixed base from master...
101 tg: Sent t/revlist/author-fixed
103 To: git@vger.kernel.org
104 Cc: gitster@pobox.com
105 Subject: [PATCH] Fix broken revlist --author when --fixed-string
107 ## Create another topic branch depending on two others non-trivially
108 $ tg create t/whatever t/revlist/author-fixed t/gitweb/nifty-links
109 tg: Creating t/whatever base from t/revlist/author-fixed...
110 tg: Merging t/whatever base with t/gitweb/nifty-links...
112 tg: Please commit merge resolution and call: tg create
113 tg: It is also safe to abort this operation using `git reset --hard`
114 tg: but please remember you are on the base branch now;
115 tg: you will want to switch to a different branch.
119 tg: Resuming t/whatever setup...
123 ## Update a single topic branch and propagate the changes to
125 $ git checkout t/gitweb/nifty-links
128 $ git checkout t/whatever
130 Topic Branch: t/whatever (1 commit)
131 Subject: [PATCH] Whatever patch
133 Depends: t/revlist/author-fixed t/gitweb/nifty-links
135 t/gitweb/nifty-links (1 commit)
137 tg: Updating base with t/gitweb/nifty-links changes...
139 tg: Please commit merge resolution and call `tg update` again.
140 tg: It is also safe to abort this operation using `git reset --hard`,
141 tg: but please remember you are on the base branch now;
142 tg: you will want to switch to a different branch.
146 tg: Updating t/whatever against new base...
148 tg: Please resolve the merge and commit. No need to do anything else.
149 tg: You can abort this operation using `git reset --hard` now
150 tg: and retry this merge later using `tg update`.
154 ## Update a single topic branch and propagate the changes
155 ## further through the dependency chain
156 $ git checkout t/gitweb/pathinfo-action
159 $ git checkout t/whatever
161 Topic Branch: t/whatever (1/2 commits)
162 Subject: [PATCH] Whatever patch
164 Depends: t/revlist/author-fixed t/gitweb/nifty-links
166 t/gitweb/pathinfo-action (<= t/gitweb/nifty-links) (1 commit)
168 tg: Recursing to t/gitweb/nifty-links...
169 [t/gitweb/nifty-links] tg: Updating base with t/gitweb/pathinfo-action changes...
171 [t/gitweb/nifty-links] tg: Please commit merge resolution and call `tg update` again.
172 [t/gitweb/nifty-links] tg: It is also safe to abort this operation using `git reset --hard`,
173 [t/gitweb/nifty-links] tg: but please remember you are on the base branch now;
174 [t/gitweb/nifty-links] tg: you will want to switch to a different branch.
175 [t/gitweb/nifty-links] tg: You are in a subshell. If you abort the merge,
176 [t/gitweb/nifty-links] tg: use `exit` to abort the recursive update altogether.
177 [t/gitweb/nifty-links] $ ..resolve..
178 [t/gitweb/nifty-links] $ git commit
179 [t/gitweb/nifty-links] $ tg update
180 [t/gitweb/nifty-links] tg: Updating t/gitweb/nifty-links against new base...
182 [t/gitweb/nifty-links] tg: Please resolve the merge and commit.
183 [t/gitweb/nifty-links] tg: You can abort this operation using `git reset --hard`.
184 [t/gitweb/nifty-links] tg: You are in a subshell. After you either commit or abort
185 [t/gitweb/nifty-links] tg: your merge, use `exit` to proceed with the recursive update.
186 [t/gitweb/nifty-links] $ ..resolve..
187 [t/gitweb/nifty-links] $ git commit
188 [t/gitweb/nifty-links] $ exit
189 tg: Updating base with t/gitweb/nifty-links changes...
190 tg: Updating t/whatever against new base...
192 ## Clone a TopGit-controlled repository
195 $ tg remote --populate origin
200 ## Add a TopGit remote to a repository and push to it
201 $ git remote add foo URL
203 $ tg push -r foo t/whatever
204 # Note that magit still uses git push, which is wrong as of TopGit 0.8
206 ## Update from a non-default TopGit remote
215 The 'tg' tool of TopGit has several subcommands:
219 Our sophisticated integrated help facility. Doesn't do
224 Create a new TopGit-controlled topic branch of a given name
225 (required argument) and switch to it. If no dependencies
226 are specified (by extra arguments passed after the first one),
227 the current branch is assumed to be the only dependency.
229 After `tg create`, you should insert the patch description
230 to the '.topmsg' file, which will already contain some
231 prefilled bits. You can set topgit.to, topgit.cc and topgit.bcc
232 configuration variables in order to have `tg create`
233 add these headers with given default values to '.topmsg'.
235 The main task of `tg create` is to set up the topic branch
236 base from the dependencies. This may fail due to merge conflicts.
237 In that case, after you commit the conflicts resolution,
238 you should call `tg create` again (without any arguments);
239 it will detect that you are on a topic branch base ref and
240 resume the topic branch creation operation.
242 In an alternative use case, if '-r BRANCH' is given instead
243 of dependency list, the topic branch is created based on
244 the given remote branch.
248 Remove a TopGit-controlled topic branch of given name
249 (required argument). Normally, this command will remove
250 only empty branch (base == head) without dependencies; use '-f'
251 to remove non-empty branch or branch that is dependent upon.
253 The '-f' option is also useful to force removal of a branch's base, if
254 you used 'git branch -D B' to remove the branch B, and then certain
255 TopGit commands complain, because the base of branch B is still there.
257 Currently, this command will _NOT_ remove the branch from
258 the dependency list in other branches. You need to take
259 care of this _manually_. This is even more complicated
260 in combination with '-f', in that case you need to manually
261 unmerge the removed branch's changes from the branches
264 TODO: '-a' to delete all empty branches, depfix, revert
268 Change dependencies of a TopGit-controlled topic branch.
269 This should have several subcommands, but only 'add' is
272 The 'add' subcommand takes an argument of a topic branch
273 to be added, adds it to '.topdeps', performs a commit and
274 then updates your topic branch accordingly. If you want to
275 do other things related to the dependency addition, like
276 adjusting '.topmsg', prepare them in the index before
277 calling 'tg depend add'.
279 TODO: Subcommand for removing dependencies, obviously
283 List files changed by the current or specified topic branch.
286 -i list files based on index instead of branch
287 -w list files based on working tree instead of branch
291 Show a summary information about the current or specified
296 Generate a patch from the current or specified topic branch.
297 This means that the diff between the topic branch base and
298 head (latest commit) is shown, appended to the description
299 found in the .topmsg file.
301 The patch is by default simply dumped to stdout. In the future,
302 tg patch will be able to automatically send the patches by mail
303 or save them to files. (TODO)
306 -i base patch generation on index instead of branch
307 -w base patch generation on working tree instead of branch
311 Send a patch from the current or specified topic branch as
314 Takes the patch given on the command line and emails it out.
315 Destination addresses such as To, Cc and Bcc are taken from the
318 Since it actually boils down to `git send-email` please refer to
319 its documentation for details on how to setup email for git.
320 You can pass arbitrary options to this command through the
321 '-s' parameter, but you must double-quote everything.
322 The '-r' parameter with msgid can be used to generate in-reply-to
323 and reference headers to an earlier mail.
325 Note: be careful when using this command. It easily sends out several
326 mails. You might want to run
328 git config sendemail.confirm always
330 to let `git send-email` ask for confirmation before sending any mail.
333 -i base patch generation on index instead of branch
334 -w base patch generation on working tree instead of branch
336 TODO: 'tg mail patchfile' to mail an already exported patch
337 TODO: mailing patch series
338 TODO: specifying additional options and addresses on command
343 Register given remote as TopGit-controlled. This will create
344 the namespace for the remote branch bases and teach 'git fetch'
345 to operate on them. However, from TopGit 0.8 onwards you need to
346 use 'tg push', or 'git push --mirror', for pushing TopGit-controlled
349 'tg remote' takes a optional remote name argument, and optional
350 '--populate' switch - use that for your origin-style remote,
351 it will seed the local topic branch system based on the
352 remote topic branches. '--populate' will also make 'tg remote'
353 automatically fetch the remote and 'tg update' to look at
354 branches of this remote for updates by default.
358 Show overview of all TopGit-tracked topic branches and their
359 up-to-date status ('>' marks the current topic branch,
360 '0' marks that it introduces no own changes,
361 'l'/'r' marks that it is local-only or has remote mate,
362 'L'/'R' marks that it is ahead/out-of-date wrt. its remote mate,
363 'D' marks that it is out-of-date wrt. its dependencies,
364 '!' marks that it has missing dependencies (even recursively),
365 'B' marks that it is out-of-date wrt. its base).
367 This can take long time to accurately determine all the relevant
368 information about each branch; you can pass '-t' to get just
369 terse list of topic branch names quickly. Alternately, you can
370 pass '--graphviz' to get a dot-suitable output to draw a dependency
371 graph between the topic branches.
373 You can also use the --sort option to sort the branches using
374 a topological sort. This is especially useful if each
375 TopGit-tracked topic branch depends on a single parent branch,
376 since it will then print the branches in the dependency
377 order. In more complex scenarios, a text graph view would be
378 much more useful, but that is not yet implemented.
380 The --deps option outputs dependency informations between
381 branches in a machine-readable format. Feed this to "tsort"
382 to get the output from --sort.
385 -i Use TopGit meta data from the index instead of branch
386 -w Use TopGit meta data from the working tree instead of branch
388 TODO: Speed up by an order of magnitude
389 TODO: Text graph view
393 Export a tidied-up history of the current topic branch
394 and its dependencies, suitable for feeding upstream.
395 Each topic branch corresponds to a single commit or patch
396 in the cleaned up history (corresponding basically exactly
397 to `tg patch` output for the topic branch).
399 The command has three possible outputs now - either a Git branch with
400 the collapsed history, a Git branch with a linearized history, or a
401 quilt series in new directory.
403 In case of producing collapsed history in new branch,
404 you can use this collapsed structure either for providing
405 a pull source for upstream, or further linearization e.g.
406 for creation of a quilt series using git log:
408 git log --pretty=email -p --topo-order origin..exported
410 To better understand the function of `tg export`,
411 consider this dependency structure of topic branches:
413 origin/master - t/foo/blue - t/foo/red - master
414 `- t/bar/good <,----------'
415 `- t/baz ------------'
417 (Where each of the branches may have hefty history.) Then
419 master$ tg export for-linus
421 will create this commit structure on branch for-linus:
423 origin/master - t/foo/blue -. merge - t/foo/red -.. merge - master
424 `- t/bar/good <,-------------------'/
425 `- t/baz ---------------------'
427 In case of using the linearize mode:
429 master$ tg export --linearize for-linus
431 you get a linear history respecting the dependencies of your patches in
432 a new branch for-linus. The result should be more or less the same as
433 using quilt mode and reimporting it into a Git branch. (More or less
434 because the topologic order can usually be extended in more than one
435 way into a complete ordering and the two methods may choose different
436 one's.) The result might be more appropriate for merging upstream as
437 it contains fewer merges.
439 Note that you might get conflicts during linearization because the
440 patches are reordered to get a linear history.
442 In case of the quilt mode,
444 master$ tg export --quilt for-linus
446 would create this directory for-linus:
448 for-linus/t/foo/blue.diff
449 for-linus/t/foo/red.diff
450 for-linus/t/bar/good.diff
458 The command works on the current topic branch
459 and can be called either without a parameter
460 (in that case, '--collapse' is assumed)
461 and with one mandatory argument: the name of the branch
462 where the exported result shall be stored.
463 The branch will be silently overwritten if it exists already!
464 Use git reflog to recover in case of mistake.
466 Alternatively, call it with the '--quilt' parameter
467 and an argument specifying the directory
468 where the quilt series should be saved.
470 With '--quilt', you can also pass '-b' parameter followed by
471 a comma-separated explicit list of branches to export. This
472 mode of operation is currently not supported with collapse.
474 In '--quilt' mode the patches are named like the originating topgit
475 branch. So usually they end up in subdirectories of the output
476 directory. With option '--flatten' the names are mangled such that
477 they end up directly in the output dir (i.e. slashes are substituted by
478 underscores). With option '--strip[=N]' the first 'N' subdirectories (all
479 if no 'N' is given) get stripped off. Names are always '--strip'ped
480 before '--flatten'ed. With option '--numbered' (which implies '--flatten')
481 the patch names get a number as prefix to allow getting the order without
482 consulting the series file, which eases sending out the patches.
484 Usage: tg export ([(--collapse | --linearize)] BRANCH | --quilt DIR)
486 TODO: Make stripping of non-essential headers configurable
487 TODO: Make stripping of [PATCH] and other prefixes configurable
488 TODO: --mbox option for other mode of operation
489 TODO: -a option to export all branches
490 TODO: For quilt exporting, export the linearized history created in a
491 temporary branch---this would allow producing conflict-less
496 Import commits within the given revision range into TopGit,
497 creating one topic branch per commit, the dependencies forming
498 a linear sequence starting on your current branch (or a branch
499 specified by the '-d' parameter).
501 The branch names are auto-guessed from the commit messages
502 and prefixed by t/ by default; use '-p PREFIX' to specify
503 an alternative prefix (even an empty one).
505 Alternatively, you can use the '-s NAME' parameter to specify
506 the name of target branch; the command will then take one more
507 argument describing a single commit to import.
511 Update the current, specified or all topic branches wrt. changes
512 in the branches they depends on and remote branches.
513 This is performed in two phases - first,
514 changes within the dependencies are merged to the base,
515 then the base is merged into the topic branch.
516 The output will guide you in case of conflicts.
518 When -a is specifed, updates all topic branches matched by
519 PATTERNs (see git-for-all-refs(1) for details) or all if
522 After the update if single topic branch was specified, it is left
523 as current; if -a was specified, returns to branch which was
524 current at the beginning.
526 In case your dependencies are not up-to-date, tg update
527 will first recurse into them and update these.
529 If a remote branch update brings dependencies on branches
530 not yet instantiated locally, you can either bring in all
531 the new branches from the remote using 'tg remote --populate'
532 or only pick out the missing ones using 'tg create -r'
533 ('tg summary' will point out branches with incomplete
534 dependencies by showing an '!' near to them).
536 TODO: tg update -a -c to autoremove (clean) up-to-date branches
540 pushes a TopGit-controlled topic branch to a remote
541 repository. By default the remote gets all dependencies
542 (both tgish and non-tgish) and bases pushed to.
546 Prints the base commit of the current topic branch. Silently
547 exits with exit code 1 if you are not working on a TopGit
552 Prints the git log of the named topgit branch.
554 Note: if you have merged changes from a different repository, this
555 command might not list all interesting commits.
559 Outputs the direct dependencies for the current or named patch.
562 -i show dependencies based on index instead of branch
563 -w show dependencies based on working tree instead of branch
567 Outputs all patches which directly depend on the current or
571 -i show dependencies based on index instead of branch
572 -w show dependencies based on working tree instead of branch
579 TopGit stores all the topic branches in the regular refs/heads/
580 namespace, (we recommend to mark them with the 't/' prefix).
581 Except that, TopGit also maintains a set of auxiliary refs in
582 refs/top-*. Currently, only refs/top-bases/ is used, containing
583 the current _base_ of the given topic branch - this is basically
584 a merge of all the branches the topic branch depends on; it is
585 updated during `tg update` and then merged to the topic branch,
586 and it is the base of a patch generated from the topic branch by
589 All the metadata is tracked within the source tree and history
590 of the topic branch itself, in .top* files; these files are kept
591 isolated within the topic branches during TopGit-controlled merges
592 and are of course omitted during `tg patch`. The state of these
593 files in base commits is undefined; look at them only in the topic
594 branches themselves. Currently, two files are defined:
596 .topmsg: Contains the description of the topic branch
597 in a mail-like format, plus the author information,
598 whatever Cc headers you choose or the post-three-dashes message.
599 When mailing out your patch, basically only few extra headers
600 mail headers are inserted and the patch itself is appended.
601 Thus, as your patches evolve, you can record nuances like whether
602 the particular patch should have To-list/Cc-maintainer or vice
603 versa and similar nuances, if your project is into that.
604 From is prefilled from your current GIT_AUTHOR_IDENT, other headers
605 can be prefilled from various optional topgit.* config options.
607 .topdeps: Contains the one-per-line list of branches
608 your patch depends on, pre-seeded with `tg create`. (Continuously
609 updated) merge of these branches will be the "base" of your topic
610 branch. DO NOT EDIT THIS FILE MANUALLY!!! If you do so, you need
611 to know exactly what are you doing, since this file must stay in
612 sync with the Git history information, otherwise very bad things
615 TopGit also automagically installs a bunch of custom commit-related
616 hooks that will verify if you are committing the .top* files in sane
617 state. It will add the hooks to separate files within the hooks/
618 subdirectory and merely insert calls of them to the appropriate hooks
619 and make them executable (but make sure the original hooks code
620 is not called if the hook was not executable beforehand).
622 Another automagically installed piece is .git/info/attributes specifier
623 for an 'ours' merge strategy for the files .topmsg and .topdeps, and
624 the (intuitive) 'ours' merge strategy definition in .git/config.
630 There are two remaining issues with accessing topic branches in remote
633 (i) Referring to remote topic branches from your local repository
634 (ii) Developing some of the remote topic branches locally
636 There are two somewhat contradictory design considerations here:
638 (a) Hacking on multiple independent TopGit remotes in a single
640 (b) Having a self-contained topic system in local refs space
642 To us, (a) does not appear to be very convincing, while (b) is quite desirable
643 for 'git-log topic' etc. working, and increased conceptual simplicity.
645 Thus, we choose to instantiate all the topic branches of given remote locally;
646 this is performed by 'tg remote --populate'.
647 'tg update' will also check if a branch can be updated from its corresponding
648 remote branch. The logic is somewhat involved if we should DTRT.
649 First, we update the base, handling the remote branch as if it was the first
650 dependency; thus, conflict resolutions made in the remote branch will be
651 carried over to our local base automagically. Then, the base is merged into
652 remote branch and the result is merged to local branch - again, to carry over
653 remote conflict resolutions. In the future, this order might be adjustable
654 per-update in case local changes are diverging more than the remote ones.
656 All commands by default refer to the remote that 'tg remote --populate'
657 was called on the last time ('topgit.remote' configuration variable). You can
658 manually run any command with a different base remote by passing '-r REMOTE'
659 _before_ the subcommand name.
665 The following references are useful to understand the development of topgit and
669 http://lists-archives.org/git/688698-add-list-and-rm-sub-commands-to-tg-depend.html