git-howto.texi 11.6 KB
Newer Older
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 9 10 11 12 13 14 15
@end titlepage

@top

@contents

@chapter Introduction

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 21 22 23 24 25 26 27 28 29 30 31 32 33 34

@example
git --help
man git
@end example

shows you the available subcommands,

@example
git <command> --help
man git-<command>
@end example

shows information about the subcommand <command>.

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 41

Consult these resources whenever you have problems, they are quite exhaustive.

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 46

@chapter Basics Usage

47
@section Get Git
48

49
You can get Git from @url{http://git-scm.com/}
50 51 52 53 54 55
Most distribution and operating system provide a package for it.


@section Cloning the source tree

@example
56
git clone git://source.ffmpeg.org/ffmpeg <target>
57 58
@end example

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 64
@end example

65
This will put the FFmpeg sources into the directory @var{<target>} and let
66 67
you push back your changes to the remote repository.

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
@example
git clone gil@@ffmpeg.org:ffmpeg-web <target>
@end example

This will put the source of the FFmpeg website into the directory
@var{<target>} and let you push back your changes to the remote repository.
(Note that @var{gil} stands for GItoLite and is not a typo of @var{git}.)

If you don't have write-access to the ffmpeg-web repository, you can
create patches after making a read-only ffmpeg-web clone:

@example
git clone git://ffmpeg.org/ffmpeg-web <target>
@end example

83 84 85 86 87 88 89 90
Make sure that you do not have Windows line endings in your checkouts,
otherwise you may experience spurious compilation failures. One way to
achieve this is to run

@example
git config --global core.autocrlf false
@end example

91

92
@anchor{Updating the source tree to the latest revision}
93 94 95 96 97 98 99 100 101 102 103
@section Updating the source tree to the latest revision

@example
git pull (--rebase)
@end example

pulls in the latest changes from the tracked branch. The tracked branch
can be remote. By default the master branch tracks the branch master in
the remote origin.

@float IMPORTANT
104
@command{--rebase} (see below) is recommended.
105 106 107 108 109 110 111 112 113 114
@end float

@section Rebasing your local branches

@example
git pull --rebase
@end example

fetches the changes from the main repository and replays your local commits
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 119 120 121 122 123 124


@section Adding/removing files/directories

@example
git add [-A] <filename/dirname>
git rm [-r] <filename/dirname>
@end example

125
Git needs to get notified of all changes you make to your working
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
directory that makes files appear or disappear.
Line moves across files are automatically tracked.


@section Showing modifications

@example
git diff <filename(s)>
@end example

will show all local modifications in your working directory as unified diff.


@section Inspecting the changelog

@example
git log <filename(s)>
@end example

145 146
You may also use the graphical tools like @command{gitview} or @command{gitk}
or the web interface available at @url{http://source.ffmpeg.org/}.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

@section Checking source tree status

@example
git status
@end example

detects all the changes you made and lists what actions will be taken in case
of a commit (additions, modifications, deletions, etc.).


@section Committing

@example
git diff --check
@end example

to double check your changes before committing them to avoid trouble later
on. All experienced developers do this on each and every commit, no matter
how small.
167

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
Every one of them has been saved from looking like a fool by this many times.
It's very easy for stray debug output or cosmetic modifications to slip in,
please avoid problems through this extra level of scrutiny.

For cosmetics-only commits you should get (almost) empty output from

@example
git diff -w -b <filename(s)>
@end example

Also check the output of

@example
git status
@end example

to make sure you don't have untracked files or deletions.

@example
git add [-i|-p|-A] <filenames/dirnames>
@end example

190
Make sure you have told Git your name and email address
191 192 193 194 195 196

@example
git config --global user.name "My Name"
git config --global user.email my@@email.invalid
@end example

197
Use @option{--global} to set the global configuration for all your Git checkouts.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

Git will select the changes to the files for commit. Optionally you can use
the interactive or the patch mode to select hunk by hunk what should be
added to the commit.


@example
git commit
@end example

Git will commit the selected changes to your current local branch.

You will be prompted for a log message in an editor, which is either
set in your personal configuration file through

@example
git config --global core.editor
@end example

or set by one of the following environment variables:
@var{GIT_EDITOR}, @var{VISUAL} or @var{EDITOR}.

Log messages should be concise but descriptive. Explain why you made a change,
what you did will be obvious from the changes themselves most of the time.
Saying just "bug fix" or "10l" is bad. Remember that people of varying skill
levels look at and educate themselves while reading through your code. Don't
include filenames in log messages, Git provides that information.

Possibly make the commit message have a terse, descriptive first line, an
empty line and then a full description. The first line will be used to name
228
the patch by @command{git format-patch}.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

@section Preparing a patchset

@example
git format-patch <commit> [-o directory]
@end example

will generate a set of patches for each commit between @var{<commit>} and
current @var{HEAD}. E.g.

@example
git format-patch origin/master
@end example

will generate patches for all commits on current branch which are not
present in upstream.
A useful shortcut is also

@example
git format-patch -n
@end example

which will generate patches from last @var{n} commits.
By default the patches are created in the current directory.

@section Sending patches for review

@example
git send-email <commit list|directory>
@end example

will send the patches created by @command{git format-patch} or directly
generates them. All the email fields can be configured in the global/local
configuration or overridden by command line.
Note that this tool must often be installed separately (e.g. @var{git-email}
package on Debian-based distros).


@section Renaming/moving/copying files or contents of files

Git automatically tracks such changes, making those normal commits.

@example
mv/cp path/file otherpath/otherfile
git add [-A] .
git commit
@end example


278 279 280
@chapter Git configuration

In order to simplify a few workflows, it is advisable to configure both
281
your personal Git installation and your local FFmpeg repository.
282 283 284 285 286 287 288 289 290 291 292 293 294 295

@section Personal Git installation

Add the following to your @file{~/.gitconfig} to help @command{git send-email}
and @command{git format-patch} detect renames:

@example
[diff]
        renames = copy
@end example

@section Repository configuration

In order to have @command{git send-email} automatically send patches
296 297
to the ffmpeg-devel mailing list, add the following stanza
to @file{/path/to/ffmpeg/repository/.git/config}:
298 299 300

@example
[sendemail]
301
        to = ffmpeg-devel@@ffmpeg.org
302 303
@end example

304
@chapter FFmpeg specific
305 306 307 308 309 310 311 312 313 314 315 316 317 318

@section Reverting broken commits

@example
git reset <commit>
@end example

@command{git reset} will uncommit the changes till @var{<commit>} rewriting
the current branch history.

@example
git commit --amend
@end example

319
allows one to amend the last commit details quickly.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

@example
git rebase -i origin/master
@end example

will replay local commits over the main repository allowing to edit, merge
or remove some of them in the process.

@float NOTE
@command{git reset}, @command{git commit --amend} and @command{git rebase}
rewrite history, so you should use them ONLY on your local or topic branches.
The main repository will reject those changes.
@end float

@example
git revert <commit>
@end example

@command{git revert} will generate a revert commit. This will not make the
faulty commit disappear from the history.

@section Pushing changes to remote trees

@example
344
git push origin master --dry-run
345 346
@end example

347 348 349
Will simulate a push of the local master branch to the default remote
(@var{origin}). And list which branches and ranges or commits would have been
pushed.
350
Git will prevent you from pushing changes if the local and remote trees are
351
out of sync. Refer to @ref{Updating the source tree to the latest revision}.
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

@example
git remote add <name> <url>
@end example

Will add additional remote with a name reference, it is useful if you want
to push your local branch for review on a remote host.

@example
git push <remote> <refspec>
@end example

Will push the changes to the @var{<remote>} repository.
Omitting @var{<refspec>} makes @command{git push} update all the remote
branches matching the local ones.

@section Finding a specific svn revision

370
Since version 1.7.1 Git supports @samp{:/foo} syntax for specifying commits
371 372 373 374 375 376
based on a regular expression. see man gitrevisions

@example
git show :/'as revision 23456'
@end example

377
will show the svn changeset @samp{r23456}. With older Git versions searching in
378 379
the @command{git log} output is the easiest option (especially if a pager with
search capabilities is used).
380

381 382 383 384 385 386
This commit can be checked out with

@example
git checkout -b svn_23456 :/'as revision 23456'
@end example

387
or for Git < 1.7.1 with
388 389 390 391 392 393 394

@example
git checkout -b svn_23456 $SHA1
@end example

where @var{$SHA1} is the commit hash from the @command{git log} output.

395

396
@chapter Pre-push checklist
397 398 399 400 401 402 403

Once you have a set of commits that you feel are ready for pushing,
work through the following checklist to doublecheck everything is in
proper order. This list tries to be exhaustive. In case you are just
pushing a typo in a comment, some of the steps may be unnecessary.
Apply your common sense, but if in doubt, err on the side of caution.

404 405 406
First, make sure that the commits and branches you are going to push
match what you want pushed and that nothing is missing, extraneous or
wrong. You can see what will be pushed by running the git push command
407
with @option{--dry-run} first. And then inspecting the commits listed with
408
@command{git log -p 1234567..987654}. The @command{git status} command
409
may help in finding local changes that have been forgotten to be added.
410

411
Next let the code pass through a full run of our test suite.
412 413 414

@itemize
@item @command{make distclean}
415
@item @command{/path/to/ffmpeg/configure}
416
@item @command{make fate}
417
@item if fate fails due to missing samples run @command{make fate-rsync} and retry
418 419
@end itemize

420
Make sure all your changes have been checked before pushing them, the
421
test suite only checks against regressions and that only to some extend. It does
422
obviously not check newly added features/code to be working unless you have
423
added a test for that (which is recommended).
424 425

Also note that every single commit should pass the test suite, not just
426
the result of a series of patches.
427

428 429 430
Once everything passed, push the changes to your public ffmpeg clone and post a
merge request to ffmpeg-devel. You can also push them directly but this is not
recommended.
431

432 433
@chapter Server Issues

434 435
Contact the project admins at @email{root@@ffmpeg.org} if you have technical
problems with the Git server.