git-howto.texi 13 KB

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