1dgit-maint-debrebase(7) dgit dgit-maint-debrebase(7)
2
3
4
6 dgit - tutorial for package maintainers, using a workflow centered
7 around git-debrebase(1)
8
10 This document describes elements of a workflow for maintaining a non-
11 native Debian package using dgit. We maintain the Debian delta as a
12 series of git commits on our master branch. We use git-debrebase(1) to
13 shuffle our branch such that this series of git commits appears at the
14 end of the branch. All the public git history is fast-forwarding,
15 i.e., we do not rewrite and force-push.
16
17 Some advantages of this workflow:
18
19 · Manipulate the delta queue using the full power of git-rebase(1),
20 instead of relying on quilt(1), and without having to switch back
21 and forth between patches-applied and patches-unapplied branches
22 when committing changes and trying to build, as with gbp-pq(1).
23
24 · If you are using 3.0 (quilt), provide your delta queue as a
25 properly separated series of quilt patches in the source package
26 that you upload to the archive (unlike with dgit-maint-merge(7)).
27
28 · Avoid the git tree being dirtied by the application or
29 unapplication of patches, as they are always applied.
30
31 · Benefit from dgit's safety catches. In particular, ensure that
32 your upload always matches exactly your git HEAD.
33
34 · Provide your full git history in a standard format on dgit-repos,
35 where it can benefit downstream dgit users, such as people using
36 dgit to do an NMU (see dgit-nmu-simple(7) and dgit-user(7)).
37
38 · Minimise the amount you need to know about 3.0 (quilt) in order to
39 maintain Debian source packages which use that format.
40
41 This workflow is appropriate for packages where the Debian delta
42 contains multiple pieces which interact, or which you don't expect to
43 be able to upstream soon. For packages with simple and/or short-lived
44 Debian deltas, use of git-debrebase(1) introduces unneeded complexity.
45 For such packages, consider the workflow described in
46 dgit-maint-merge(7).
47
49 This section explains how to start using this workflow with a new
50 package. It should be skipped when converting an existing package to
51 this workflow.
52
53 When upstream tags releases in git
54 Suppose that the latest stable upstream release is 1.2.2, and this has
55 been tagged '1.2.2' by upstream.
56
57 % git clone -oupstream https://some.upstream/foo.git
58 % cd foo
59 % git verify-tag 1.2.2
60 % git reset --hard 1.2.2
61 % git branch --unset-upstream
62
63 The final command detaches your master branch from the upstream remote,
64 so that git doesn't try to push anything there, or merge unreleased
65 upstream commits. To maintain a copy of your packaging branch on
66 salsa.debian.org in addition to dgit-repos, you can do something like
67 this:
68
69 % git remote add -f origin salsa.debian.org:Debian/foo.git
70 % git push --follow-tags -u origin master
71
72 Now go ahead and Debianise your package. Make commits on the master
73 branch, adding things in the debian/ directory, or patching the
74 upstream source. For technical reasons, it is essential that your
75 first commit introduces the debian/ directory containing at least one
76 file, and does nothing else. In other words, make a commit introducing
77 debian/ before patching the upstream source.
78
79 Finally, you need an orig tarball:
80
81 % git deborig
82
83 See git-deborig(1) if this fails.
84
85 This tarball is ephemeral and easily regenerated, so we don't commit it
86 anywhere (e.g. with tools like pristine-tar(1)).
87
88 Comparing upstream's tarball releases
89
90 The above assumes that you know how to build the package from git
91 and that doing so is straightforward.
92
93 If, as a user of the upstream source, you usually build from
94 upstream tarball releases, rather than upstream git tags, you will
95 sometimes find that the git tree doesn't contain everything that is
96 in the tarball.
97
98 Additional build steps may be needed. For example, you may need
99 your debian/rules to run autotools.
100
101 You can compare the upstream tarball release, and upstream git tag,
102 within git, by importing the tarball into git as described in the
103 next section, using a different value for 'upstream-tag', and then
104 using git-diff(1) to compare the imported tarball to the release
105 tag.
106
107 When upstream releases only tarballs
108 Because we want to work in git, we need a virtual upstream branch with
109 virtual release tags. gbp-import-orig(1) can manage this for us. To
110 begin
111
112 % mkdir foo
113 % cd foo
114 % git init
115
116 Now create debian/gbp.conf:
117
118 [DEFAULT]
119 upstream-branch = upstream
120 debian-branch = master
121 upstream-tag = %(version)s
122
123 sign-tags = True
124 pristine-tar = False
125 pristine-tar-commit = False
126
127 [import-orig]
128 merge-mode = merge
129
130 gbp-import-orig(1) requires a pre-existing upstream branch:
131
132 % git add debian/gbp.conf && git commit -m "create gbp.conf"
133 % git checkout --orphan upstream
134 % git rm -rf .
135 % git commit --allow-empty -m "initial, empty branch for upstream source"
136 % git checkout -f master
137
138 Then we can import the upstream version:
139
140 % gbp import-orig --merge-mode=replace ../foo_1.2.2.orig.tar.xz
141
142 Our upstream branch cannot be pushed to dgit-repos, but since we will
143 need it whenever we import a new upstream version, we must push it
144 somewhere. The usual choice is salsa.debian.org:
145
146 % git remote add -f origin salsa.debian.org:Debian/foo.git
147 % git push --follow-tags -u origin master upstream
148
149 You are now ready to proceed as above, making commits to the debian/
150 directory and to the upstream source. As above, for technical reasons,
151 it is essential that your first commit introduces the debian/ directory
152 containing at least one file, and does nothing else. In other words,
153 make a commit introducing debian/ before patching the upstream source.
154
156 This section explains how to convert an existing Debian package to this
157 workflow. It should be skipped when debianising a new package.
158
159 If you have an existing git history that you have pushed to an ordinary
160 git server like salsa.debian.org, we start with that. If you don't
161 already have it locally, you'll need to clone it, and obtain the
162 corresponding orig.tar from the archive:
163
164 % git clone salsa.debian.org:Debian/foo
165 % cd foo
166 % dgit setup-new-tree
167 % origtargz
168
169 If you don't have any existing git history, or you have history only on
170 the special dgit-repos server, we start with dgit clone:
171
172 % dgit clone foo
173 % cd foo
174
175 Then we make new upstream tags available:
176
177 % git remote add -f upstream https://some.upstream/foo.git
178
179 We now use a git debrebase convert-from-* command to convert your
180 existing history to the git-debrebase(5) data model. Which command you
181 should use depends on some facts about your repository:
182
183 (A) There is no delta queue.
184 If there do not exist any Debian patches, use
185
186 % git debrebase convert-from-gbp
187
188 (B) There is a delta queue, and patches are unapplied.
189 This is the standard git-buildpackage(1) workflow: there are Debian
190 patches, but the upstream source is committed to git without those
191 patches applied. Use
192
193 % git debrebase convert-from-gbp
194
195 If you were not previously using dgit to upload your package (i.e.
196 you were not using the workflow described in dgit-maint-gbp(7)),
197 and you happen to have run dgit fetch sid in this clone of the
198 repository, you will need to pass --fdiverged to this command.
199
200 (C) There is a delta queue, and patches are applied.
201 Use
202
203 % git debrebase convert-from-dgit-view
204
205 Finally, you need to ensure that your git HEAD is dgit-compatible,
206 i.e., it is exactly what you would get if you deleted .git, invoked
207 dpkg-buildpackage -S, and then unpacked the resultant source package.
208
209 To achieve this, you might need to delete debian/source/local-options.
210 One way to have dgit check your progress is to run dgit build-source.
211
213 git-debrebase(1) does not yet support using git merge to merge
214 divergent branches of development (see "OTHER MERGES" in
215 git-debrebase(5)). You should configure git such that git pull does
216 not try to merge:
217
218 % git config --local pull.rebase true
219
220 Now when you pull work from other Debian contributors, git will rebase
221 your work on top of theirs.
222
223 If you use this clone for upstream development in addition to Debian
224 packaging work, you may not want to set this global setting. Instead,
225 see the branch.autoSetupRebase and branch.<name>.rebase settings in
226 git-config(5).
227
229 There are two steps: obtaining git refs that correspond to the new
230 release, and importing that release using git-debrebase(1).
231
232 Obtaining the release
233 When upstream tags releases in git
234
235 % git remote update
236
237 When upstream releases only tarballs
238
239 You will need the debian/gbp.conf from "When upstream releases only
240 tarballs", above. You will also need your upstream branch. Above, we
241 pushed this to salsa.debian.org. You will need to clone or fetch from
242 there, instead of relying on dgit clone/dgit fetch alone.
243
244 Then, either
245
246 % gbp import-orig --no-merge ../foo_1.2.3.orig.tar.xz
247
248 or if you have a working watch file
249
250 % gbp import-orig --no-merge --uscan
251
252 Importing the release
253 % git debrebase new-upstream 1.2.3
254
255 This invocation of git-debrebase(1) involves a git rebase. You may
256 need to resolve conflicts if the Debian delta queue does not apply
257 cleanly to the new upstream source.
258
259 If all went well, you can now review the merge of the new upstream
260 release:
261
262 git diff debian/1.2.2-1..HEAD -- . ':!debian'
263
264 Pass --stat just to see the list of changed files, which is useful to
265 determine whether there are any new or deleted files that may need
266 accounting for in your copyright file.
267
268 If you obtained a tarball from upstream, you are ready to try a build.
269 If you merged a git tag from upstream, you will first need to generate
270 a tarball:
271
272 % git deborig
273
275 Just make commits on master that change the contents of debian/.
276
278 Adding new patches
279 Adding new patches is straightforward: just make commits touching only
280 files outside of the debian/ directory. You can also use tools like
281 git-revert(1), git-am(1) and git-cherry-pick(1).
282
283 Editing patches: starting a debrebase
284 git-debrebase(1) is a wrapper around git-rebase(1) which allows us to
285 edit, re-order and delete patches. Run
286
287 % git debrebase -i
288
289 to start an interactive rebase. You can edit, re-order and delete
290 commits just as you would during git rebase -i.
291
292 Editing patches: finishing a debrebase
293 After completing the git rebase, your branch will not be a fast-forward
294 of the git HEAD you had before the rebase. This means that we cannot
295 push the branch anywhere. If you are ready to upload, dgit push or
296 dgit push-source will take care of fixing this up for you.
297
298 If you are not yet ready to upload, and want to push your branch to a
299 git remote such as salsa.debian.org,
300
301 % git debrebase conclude
302
303 Note that each time you conclude a debrebase you introduce a
304 pseudomerge into your git history, which may make it harder to read.
305 Try to do all of the editing of the delta queue that you think will be
306 needed for this editing session in a single debrebase, so that there is
307 a single debrebase stitch.
308
310 You can use dpkg-buildpackage(1) for test builds. When you are ready
311 to build for an upload, use dgit sbuild, dgit pbuilder or dgit
312 cowbuilder.
313
314 Upload with dgit push or dgit push-source. Remember to pass --new if
315 the package is new in the target suite.
316
317 In some cases where you used git debrebase convert-from-gbp since the
318 last upload, it is not possible for dgit to make your history fast-
319 forwarding from the history on dgit-repos. In such cases you will have
320 to pass --overwrite to dgit. git-debrebase will normally tell you if
321 this will be needed.
322
323 Right before uploading, if you did not just already do so, you might
324 want to have git-debrebase(1) shuffle your branch such that the Debian
325 delta queue appears right at the tip of the branch you will push:
326
327 % git debrebase
328 % dgit push-source
329
330 Note that this will introduce a new pseudomerge.
331
332 After dgit pushing, be sure to git push to salsa.debian.org, if you're
333 using that.
334
336 Illegal material
337 Here we explain how to handle material that is merely DFSG-non-free.
338 Material which is legally dangerous (for example, files which are
339 actually illegal) cannot be handled this way.
340
341 If you encounter possibly-legally-dangerous material in the upstream
342 source code you should seek advice. It is often best not to make a
343 fuss on a public mailing list (at least, not at first). Instead, email
344 your archive administrators. For Debian that is
345 To: dgit-owner@debian.org, ftpmaster@ftp-master.debian.org
346
347 DFSG-non-free: When upstream tags releases in git
348 Our approach is to maintain a DFSG-clean upstream branch, and create
349 tags on this branch for each release that we want to import. We then
350 import those tags per "Importing the release", above. In the case of a
351 new package, we base our initial Debianisation on our first DFSG-clean
352 tag.
353
354 For the first upstream release that requires DFSG filtering:
355
356 % git checkout -b upstream-dfsg 1.2.3
357 % git rm evil.bin
358 % git commit -m "upstream version 1.2.3 DFSG-cleaned"
359 % git tag -s 1.2.3+dfsg
360 % git checkout master
361
362 Now either proceed with "Importing the release" on the 1.2.3+dfsg tag,
363 or in the case of a new package,
364
365 % git branch --unset-upstream
366 % git reset --hard 1.2.3+dfsg
367
368 and proceed with "INITIAL DEBIANISATION".
369
370 For subsequent releases (whether or not they require additional
371 filtering):
372
373 % git checkout upstream-dfsg
374 % git merge 1.2.4
375 % git rm further-evil.bin # if needed
376 % git commit -m "upstream version 1.2.4 DFSG-cleaned" # if needed
377 % git tag -s 1.2.4+dfsg
378 % git checkout master
379 % # proceed with "Importing the release" on 1.2.4+dfsg tag
380
381 Our upstream-dfsg branch cannot be pushed to dgit-repos, but since we
382 will need it whenever we import a new upstream version, we must push it
383 somewhere. Assuming that you have already set up an origin remote per
384 the above,
385
386 % git push --follow-tags -u origin master upstream-dfsg
387
388 DFSG-non-free: When upstream releases only tarballs
389 The easiest way to handle this is to add a Files-Excluded field to
390 debian/copyright, and a uversionmangle setting in debian/watch. See
391 uscan(1). Alternatively, see the --filter option detailed in
392 gbp-import-orig(1).
393
395 In the simplest case,
396
397 % dgit fetch
398 % git merge --ff-only dgit/dgit/sid
399
400 If that fails, because your branch and the NMUers' work represent
401 divergent branches of development, you have a number of options. Here
402 we describe the two simplest.
403
404 Note that you should not try to resolve the divergent branches by
405 editing files in debian/patches. Changes there would either cause
406 trouble, or be overwritten by git-debrebase(1).
407
408 Rebasing your work onto the NMU
409 % git rebase dgit/dgit/sid
410
411 If the NMUer added new commits modifying the upstream source, you will
412 probably want to debrebase before your next upload to tidy those up.
413
414 For example, the NMUer might have used git-revert(1) to unapply one of
415 your patches. A debrebase can be used to strip both the patch and the
416 reversion from the delta queue.
417
418 Manually applying the debdiff
419 If you cannot rebase because you have already pushed to
420 salsa.debian.org, say, you can manually apply the NMU debdiff, commit
421 and debrebase. The next dgit push will require --overwrite.
422
424 Minimising pseudomerges
425 Above we noted that each time you conclude a debrebase, you introduce a
426 pseudomerge into your git history, which may make it harder to read.
427
428 A simple convention you can use to minimise the number of pseudomerges
429 is to git debrebase conclude only right before you upload or push to
430 salsa.debian.org.
431
432 It is possible, though much less convenient, to reduce the number of
433 pseudomerges yet further. We debrebase only (i) when importing a new
434 release, and (ii) right before uploading. Instead of editing the
435 existing delta queue, you append fixup commits (and reversions of
436 commits) that alter the upstream source to the required state. You can
437 push and pull to and from salsa.debian.org during this. Just before
438 uploading, you debrebase, once, to tidy everything up.
439
440 The debian/patches directory
441 In this workflow, debian/patches is purely an output of
442 git-debrebase(1). You should not make changes there. They will either
443 cause trouble, or be ignored and overwritten by git-debrebase(1).
444
445 debian/patches will often be out-of-date because git-debrebase(1) will
446 only regenerate it when it needs to. So you should not rely on the
447 information in that directory. When preparing patches to forward
448 upstream, you should use git-format-patch(1) on git commits, rather
449 than sending files from debian/patches.
450
451 Upstream branches
452 In this workflow, we specify upstream tags rather than any branches.
453
454 Except when (i) upstream releases only tarballs, (ii) we require DFSG
455 filtering, or (iii) you also happen to be involved in upstream
456 development, we do not maintain any local branch corresponding to
457 upstream, except temporary branches used to prepare patches for
458 forwarding, and the like.
459
460 The idea here is that from Debian's point of view, upstream releases
461 are immutable points in history. We want to make sure that we are
462 basing our Debian package on a properly identified upstream version,
463 rather than some arbitrary commit on some branch. Tags are more useful
464 for this.
465
466 Upstream's branches remain available as the git remote tracking
467 branches for your upstream remote, e.g. remotes/upstream/master.
468
469 The first ever dgit push
470 If this is the first ever dgit push of the package, consider passing
471 --deliberately-not-fast-forward instead of --overwrite. This avoids
472 introducing a new origin commit into your git history. (This origin
473 commit would represent the most recent non-dgit upload of the package,
474 but this should already be represented in your git history.)
475
476 Inspecting the history
477 The git history made by git-debrebase can seem complicated. Here are
478 some suggestions for helpful invocations of gitk and git. They can be
479 adapted for other tools like tig(1), git-log(1), magit, etc.
480
481 History of package in Debian, disregarding history from upstream:
482
483 % gitk --first-parent
484
485 In a laundered branch, the delta queue is at the top.
486
487 History of the packaging, excluding the delta queue:
488
489 % gitk :/debian :!/debian/patches
490
491 Just the delta queue (i.e. Debian's changes to upstream):
492
493 % gitk --first-parent -- :/ :!/debian
494
495 Full history including old versions of the delta queue:
496
497 % gitk --date-order
498
499 The "Declare fast forward" commits you see have an older history
500 (usually, an older delta queue) as one parent, and a newer history
501 as the other. --date-order makes gitk show the delta queues in the
502 right order.
503
504 Complete diff since the last upload:
505
506 % git diff dgit/dgit/sid..HEAD -- :/ :!/debian/patches
507
508 This includes changes to upstream files.
509
510 Interdiff of delta queue since last upload, if you really want it:
511
512 % git debrebase make-patches
513 % git diff dgit/dgit/sid..HEAD -- debian/patches
514
515 And of course there is:
516
517 % git debrebase status
518
519 Alternative ways to start a debrebase
520 Above we started an interactive debrebase by invoking git-debrebase(1)
521 like this:
522
523 % git debrebase -i
524
525 It is also possible to perform a non-interactive rebase, like this:
526
527 % git debrebase -- [git-rebase options...]
528
529 A third alternative is to have git-debrebase(1) shuffle all the Debian
530 changes to the end of your branch, and then manipulate them yourself
531 using git-rebase(1) directly. For example,
532
533 % git debrebase
534 % git rebase -i HEAD~5 # there are 4 Debian patches
535
536 If you take this approach, you should be very careful not to start the
537 rebase too early, including before the most recent pseudomerge. git-
538 rebase without a base argument will often start the rebase too early,
539 and should be avoided. Run git-debrebase instead. See also "ILLEGAL
540 OPERATIONS" in git-debrebase(5).
541
543 dgit(1), dgit(7), git-debrebase(1), git-debrebase(5)
544
546 This tutorial was written and is maintained by Sean Whitton
547 <spwhitton@spwhitton.name>. It contains contributions from other dgit
548 contributors too - see the dgit copyright file.
549
550
551
552perl v5.28.1 Debian Project dgit-maint-debrebase(7)