git-howto.texi 11 KB

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