You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
12KB

  1. \input texinfo @c -*- texinfo -*-
  2. @settitle Using git to develop Libav
  3. @titlepage
  4. @center @titlefont{Using git to develop Libav}
  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 Libav-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://git.libav.org/libav.git <target>
  36. @end example
  37. This will put the Libav sources into the directory @var{<target>}.
  38. @example
  39. git clone git@@git.libav.org:libav.git <target>
  40. @end example
  41. This will put the Libav 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. Since merge commits are forbidden @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. Libav'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://git.libav.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 Libav 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 libav-devel mailing list, add the following stanza
  187. to @file{/path/to/libav/repository/.git/config}:
  188. @example
  189. [sendemail]
  190. to = libav-devel@@libav.org
  191. @end example
  192. @chapter Libav 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 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 your Git repository is on a branch that is a direct
  261. descendant of the Libav master branch, which is the only one from which
  262. pushing to Libav is possible. Then run the following command:
  263. @itemize
  264. @item @command{git log --patch --stat origin/master..}
  265. to make sure that only the commits you want to push are pending, that
  266. the log messages of the commits are correct and descriptive and contain
  267. no cruft from @command{git am} and to doublecheck that the commits you
  268. want to push really only contain the changes they are supposed to contain.
  269. @item @command{git status}
  270. to ensure no local changes still need to be committed and that no local
  271. changes may have thrown off the results of your testing.
  272. @end itemize
  273. Next let the code pass through a full run of our test suite. Before you do,
  274. the command @command{make fate-rsync} will update the test samples. Changes
  275. to the samples set are not very common and commits depending on samples
  276. changes are delayed for at least 24 hours to allow the new samples to
  277. propagate, so updating it once per day is sufficient. Now execute
  278. @itemize
  279. @item @command{make distclean}
  280. @item @command{/path/to/libav/configure}
  281. @item @command{make check}
  282. @end itemize
  283. While the test suite covers a wide range of possible problems, it is not
  284. a panacea. Do not hesitate to perform any other tests necessary to convince
  285. yourself that the changes you are about to push actually work as expected.
  286. Also note that every single commit should pass the test suite, not just
  287. the result of a series of patches. So if you have a series of commits
  288. to push, run the test suite on every single commit.
  289. Give other developers a reasonable amount of time to look at and review
  290. patches before you push them. Not everybody is online 24/7, but may wish
  291. to look at and comment on a patch nonetheless. The time you leave depends
  292. on the urgency and complexity of the patch. Use your common sense to pick
  293. a timeframe that allows everybody that you think may wish to comment
  294. and/or should comment on the change an opportunity to see it.
  295. Finally, after pushing, mark all patches as committed on
  296. @url{http://patches.libav.org/,patchwork}.
  297. Sometimes this is not automatically done when a patch has been
  298. slightly modified from the version on the mailing list.
  299. Also update previous incarnations of the patches you push so that
  300. patchwork is not cluttered with cruft.
  301. @chapter Server Issues
  302. Contact the project admins @email{git@@libav.org} if you have technical
  303. problems with the GIT server.