1\input texinfo @c -*- texinfo -*-
2@documentencoding UTF-8
3
4@settitle Using Git to develop FFmpeg
5
6@titlepage
7@center @titlefont{Using Git to develop FFmpeg}
8@end titlepage
9
10@top
11
12@contents
13
14@chapter Introduction
15
16This document aims in giving some quick references on a set of useful Git
17commands. You should always use the extensive and detailed documentation
18provided directly by Git:
19
20@example
21git --help
22man git
23@end example
24
25shows you the available subcommands,
26
27@example
28git <command> --help
29man git-<command>
30@end example
31
32shows information about the subcommand <command>.
33
34Additional information could be found on the
35@url{http://gitref.org, Git Reference} website.
36
37For more information about the Git project, visit the
38@url{http://git-scm.com/, Git website}.
39
40Consult these resources whenever you have problems, they are quite exhaustive.
41
42What follows now is a basic introduction to Git and some FFmpeg-specific
43guidelines to ease the contribution to the project.
44
45@chapter Basics Usage
46
47@section Get Git
48
49You can get Git from @url{http://git-scm.com/}
50Most distribution and operating system provide a package for it.
51
52
53@section Cloning the source tree
54
55@example
56git clone https://git.ffmpeg.org/ffmpeg.git <target>
57@end example
58
59This will put the FFmpeg sources into the directory @var{<target>}.
60
61@example
62git clone git@@source.ffmpeg.org:ffmpeg <target>
63@end example
64
65This will put the FFmpeg sources into the directory @var{<target>} and let
66you push back your changes to the remote repository.
67
68@example
69git clone gil@@ffmpeg.org:ffmpeg-web <target>
70@end example
71
72This will put the source of the FFmpeg website into the directory
73@var{<target>} and let you push back your changes to the remote repository.
74(Note that @var{gil} stands for GItoLite and is not a typo of @var{git}.)
75
76If you don't have write-access to the ffmpeg-web repository, you can
77create patches after making a read-only ffmpeg-web clone:
78
79@example
80git clone git://ffmpeg.org/ffmpeg-web <target>
81@end example
82
83Make sure that you do not have Windows line endings in your checkouts,
84otherwise you may experience spurious compilation failures. One way to
85achieve this is to run
86
87@example
88git config --global core.autocrlf false
89@end example
90
91
92@anchor{Updating the source tree to the latest revision}
93@section Updating the source tree to the latest revision
94
95@example
96git pull (--rebase)
97@end example
98
99pulls in the latest changes from the tracked branch. The tracked branch
100can be remote. By default the master branch tracks the branch master in
101the remote origin.
102
103@float IMPORTANT
104@command{--rebase} (see below) is recommended.
105@end float
106
107@section Rebasing your local branches
108
109@example
110git pull --rebase
111@end example
112
113fetches the changes from the main repository and replays your local commits
114over it. This is required to keep all your local changes at the top of
115FFmpeg's master tree. The master tree will reject pushes with merge commits.
116
117
118@section Adding/removing files/directories
119
120@example
121git add [-A] <filename/dirname>
122git rm [-r] <filename/dirname>
123@end example
124
125Git needs to get notified of all changes you make to your working
126directory that makes files appear or disappear.
127Line moves across files are automatically tracked.
128
129
130@section Showing modifications
131
132@example
133git diff <filename(s)>
134@end example
135
136will show all local modifications in your working directory as unified diff.
137
138
139@section Inspecting the changelog
140
141@example
142git log <filename(s)>
143@end example
144
145You may also use the graphical tools like @command{gitview} or @command{gitk}
146or the web interface available at @url{http://source.ffmpeg.org/}.
147
148@section Checking source tree status
149
150@example
151git status
152@end example
153
154detects all the changes you made and lists what actions will be taken in case
155of a commit (additions, modifications, deletions, etc.).
156
157
158@section Committing
159
160@example
161git diff --check
162@end example
163
164to double check your changes before committing them to avoid trouble later
165on. All experienced developers do this on each and every commit, no matter
166how small.
167
168Every one of them has been saved from looking like a fool by this many times.
169It's very easy for stray debug output or cosmetic modifications to slip in,
170please avoid problems through this extra level of scrutiny.
171
172For cosmetics-only commits you should get (almost) empty output from
173
174@example
175git diff -w -b <filename(s)>
176@end example
177
178Also check the output of
179
180@example
181git status
182@end example
183
184to make sure you don't have untracked files or deletions.
185
186@example
187git add [-i|-p|-A] <filenames/dirnames>
188@end example
189
190Make sure you have told Git your name, email address and GPG key
191
192@example
193git config --global user.name "My Name"
194git config --global user.email my@@email.invalid
195git config --global user.signingkey ABCDEF0123245
196@end example
197
198Enable signing all commits or use -S
199
200@example
201git config --global commit.gpgsign true
202@end example
203
204Use @option{--global} to set the global configuration for all your Git checkouts.
205
206Git will select the changes to the files for commit. Optionally you can use
207the interactive or the patch mode to select hunk by hunk what should be
208added to the commit.
209
210
211@example
212git commit
213@end example
214
215Git will commit the selected changes to your current local branch.
216
217You will be prompted for a log message in an editor, which is either
218set in your personal configuration file through
219
220@example
221git config --global core.editor
222@end example
223
224or set by one of the following environment variables:
225@var{GIT_EDITOR}, @var{VISUAL} or @var{EDITOR}.
226
227@section Writing a commit message
228
229Log messages should be concise but descriptive.
230
231The first line must contain the context, a colon and a very short
232summary of what the commit does. Details can be added, if necessary,
233separated by an empty line. These details should not exceed 60-72 characters
234per line, except when containing code.
235
236Example of a good commit message:
237
238@example
239avcodec/cbs: add a helper to read extradata within packet side data
240
241Using ff_cbs_read() on the raw buffer will not parse it as extradata,
242resulting in parsing errors for example when handling ISOBMFF avcC.
243This helper works around that.
244@end example
245
246@example
247ptr might be NULL
248@end example
249
250If the summary on the first line is not enough, in the body of the message,
251explain why you made a change, what you did will be obvious from the changes
252themselves most of the time. Saying just "bug fix" or "10l" is bad. Remember
253that people of varying skill levels look at and educate themselves while
254reading through your code. Don't include filenames in log messages except in
255the context, Git provides that information.
256
257If the commit fixes a registered issue, state it in a separate line of the
258body: @code{Fix Trac ticket #42.}
259
260The first line will be used to name
261the patch by @command{git format-patch}.
262
263Common mistakes for the first line, as seen in @command{git log --oneline}
264include: missing context at the beginning; description of what the code did
265before the patch; line too long or wrapped to the second line.
266
267@section Preparing a patchset
268
269@example
270git format-patch <commit> [-o directory]
271@end example
272
273will generate a set of patches for each commit between @var{<commit>} and
274current @var{HEAD}. E.g.
275
276@example
277git format-patch origin/master
278@end example
279
280will generate patches for all commits on current branch which are not
281present in upstream.
282A useful shortcut is also
283
284@example
285git format-patch -n
286@end example
287
288which will generate patches from last @var{n} commits.
289By default the patches are created in the current directory.
290
291@section Sending patches for review
292
293@example
294git send-email <commit list|directory>
295@end example
296
297will send the patches created by @command{git format-patch} or directly
298generates them. All the email fields can be configured in the global/local
299configuration or overridden by command line.
300Note that this tool must often be installed separately (e.g. @var{git-email}
301package on Debian-based distros).
302
303
304@section Renaming/moving/copying files or contents of files
305
306Git automatically tracks such changes, making those normal commits.
307
308@example
309mv/cp path/file otherpath/otherfile
310git add [-A] .
311git commit
312@end example
313
314
315@chapter Git configuration
316
317In order to simplify a few workflows, it is advisable to configure both
318your personal Git installation and your local FFmpeg repository.
319
320@section Personal Git installation
321
322Add the following to your @file{~/.gitconfig} to help @command{git send-email}
323and @command{git format-patch} detect renames:
324
325@example
326[diff]
327        renames = copy
328@end example
329
330@section Repository configuration
331
332In order to have @command{git send-email} automatically send patches
333to the ffmpeg-devel mailing list, add the following stanza
334to @file{/path/to/ffmpeg/repository/.git/config}:
335
336@example
337[sendemail]
338        to = ffmpeg-devel@@ffmpeg.org
339@end example
340
341@chapter FFmpeg specific
342
343@section Reverting broken commits
344
345@example
346git reset <commit>
347@end example
348
349@command{git reset} will uncommit the changes till @var{<commit>} rewriting
350the current branch history.
351
352@example
353git commit --amend
354@end example
355
356allows one to amend the last commit details quickly.
357
358@example
359git rebase -i origin/master
360@end example
361
362will replay local commits over the main repository allowing to edit, merge
363or remove some of them in the process.
364
365@float NOTE
366@command{git reset}, @command{git commit --amend} and @command{git rebase}
367rewrite history, so you should use them ONLY on your local or topic branches.
368The main repository will reject those changes.
369@end float
370
371@example
372git revert <commit>
373@end example
374
375@command{git revert} will generate a revert commit. This will not make the
376faulty commit disappear from the history.
377
378@section Pushing changes to remote trees
379
380@example
381git push origin master --dry-run
382@end example
383
384Will simulate a push of the local master branch to the default remote
385(@var{origin}). And list which branches and ranges or commits would have been
386pushed.
387Git will prevent you from pushing changes if the local and remote trees are
388out of sync. Refer to @ref{Updating the source tree to the latest revision}.
389
390@example
391git remote add <name> <url>
392@end example
393
394Will add additional remote with a name reference, it is useful if you want
395to push your local branch for review on a remote host.
396
397@example
398git push <remote> <refspec>
399@end example
400
401Will push the changes to the @var{<remote>} repository.
402Omitting @var{<refspec>} makes @command{git push} update all the remote
403branches matching the local ones.
404
405@section Finding a specific svn revision
406
407Since version 1.7.1 Git supports @samp{:/foo} syntax for specifying commits
408based on a regular expression. see man gitrevisions
409
410@example
411git show :/'as revision 23456'
412@end example
413
414will show the svn changeset @samp{r23456}. With older Git versions searching in
415the @command{git log} output is the easiest option (especially if a pager with
416search capabilities is used).
417
418This commit can be checked out with
419
420@example
421git checkout -b svn_23456 :/'as revision 23456'
422@end example
423
424or for Git < 1.7.1 with
425
426@example
427git checkout -b svn_23456 $SHA1
428@end example
429
430where @var{$SHA1} is the commit hash from the @command{git log} output.
431
432
433@chapter gpg key generation
434
435If you have no gpg key yet, we recommend that you create a ed25519 based key as it
436is small, fast and secure. Especially it results in small signatures in git.
437
438@example
439gpg --default-new-key-algo "ed25519/cert,sign+cv25519/encr" --quick-generate-key "human@@server.com"
440@end example
441
442When generating a key, make sure the email specified matches the email used in git as some sites like
443github consider mismatches a reason to declare such commits unverified. After generating a key you
444can add it to the MAINTAINER file and upload it to a keyserver.
445
446@chapter Pre-push checklist
447
448Once you have a set of commits that you feel are ready for pushing,
449work through the following checklist to doublecheck everything is in
450proper order. This list tries to be exhaustive. In case you are just
451pushing a typo in a comment, some of the steps may be unnecessary.
452Apply your common sense, but if in doubt, err on the side of caution.
453
454First, make sure that the commits and branches you are going to push
455match what you want pushed and that nothing is missing, extraneous or
456wrong. You can see what will be pushed by running the git push command
457with @option{--dry-run} first. And then inspecting the commits listed with
458@command{git log -p 1234567..987654}. The @command{git status} command
459may help in finding local changes that have been forgotten to be added.
460
461Next let the code pass through a full run of our test suite.
462
463@itemize
464@item @command{make distclean}
465@item @command{/path/to/ffmpeg/configure}
466@item @command{make fate}
467@item if fate fails due to missing samples run @command{make fate-rsync} and retry
468@end itemize
469
470Make sure all your changes have been checked before pushing them, the
471test suite only checks against regressions and that only to some extend. It does
472obviously not check newly added features/code to be working unless you have
473added a test for that (which is recommended).
474
475Also note that every single commit should pass the test suite, not just
476the result of a series of patches.
477
478Once everything passed, push the changes to your public ffmpeg clone and post a
479merge request to ffmpeg-devel. You can also push them directly but this is not
480recommended.
481
482@chapter Server Issues
483
484Contact the project admins at @email{root@@ffmpeg.org} if you have technical
485problems with the Git server.
486