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