]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/contributor/source-code.itexi
Doc-fr: add tempo-ranges feature to NR 1.2 Rhythms
[lilypond.git] / Documentation / contributor / source-code.itexi
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3
4 @node Working with source code
5 @chapter Working with source code
6
7 New contributors should only read @ref{Using lily-git}.  Please
8 ignore the rest of this chapter.
9
10 Advanced contributors will find the rest of this material quite
11 useful, particularly if they are working on major new features.
12
13 @menu
14 * Using lily-git::
15 * Starting with Git::
16 * Basic Git procedures::
17 * Advanced Git procedures::
18 * Git on Windows::
19 * Repository directory structure::
20 * Other Git documentation::
21 @end menu
22
23
24 @c if you change this node name, you'll need to change the @ref in
25 @c web/ and/or included/, along with all the translations.
26 @node Using lily-git
27 @section Using lily-git
28
29 @command{lily-git.tcl} is a graphical tool to help you access and
30 share changes to the lilypond source code.
31
32 @menu
33 * Install and configuration of lily-git.tcl::
34 * Daily use of lily-git.tcl::
35 @end menu
36
37 @node Install and configuration of lily-git.tcl
38 @unnumberedsubsec Install and configuration of @command{lily-git.tcl}
39
40 @enumerate
41 @item
42 If you haven't already, download and install Git.
43
44 @itemize
45
46 @item
47 Lilybuntu users: git has already been installed for you.
48
49 @item Windows users: download the @code{.exe} file labeled
50 @qq{Full installer for official Git} from:
51
52 @example
53 @uref{http://code.google.com/p/msysgit/downloads/list}
54 @end example
55
56 @item Other operating systems: either install @command{git} with
57 your package manager, or download it from the @qq{Binaries}
58 section of:
59
60 @example
61 @uref{http://git-scm.com/download}
62 @end example
63
64 @end itemize
65
66
67 @item
68 Download the @command{lily-git.tcl} script from:
69
70 @c don't change the cgit link below to gitweb; gitweb uses
71 @c long filenames like "scripts_auxiliar_lily-git.tcl"
72
73 @example
74 @uref{http://git.sv.gnu.org/cgit/lilypond.git/plain/scripts/auxiliar/lily-git.tcl}
75 @end example
76
77 @item
78 To run the program from the command line, navigate to the
79 directory containing @command{lily-git.tcl} and enter:
80
81 @example
82 wish lily-git.tcl
83 @end example
84
85 @item
86 Click on the @qq{Get source} button.
87
88 This will create a directory called @file{lilypond-git/} within
89 your home directory, and will download the source code into that
90 directory (around 55Mb).  When the process is finished, the
91 @qq{Command output} window will display @qq{Done}, and the button
92 label will change to say @qq{Update source}.
93
94 @item
95 Navigate to the @file{lilypond-git/} directory to view the source
96 files.  You should now be able to modify the source files using
97 your normal text editor.
98
99 @end enumerate
100
101 @quotation
102 Advanced note: The @qq{Get source} button does not fetch the
103 entire history of the git repository, so utilities like
104 @command{gitk} will only be able to display the most recent
105 additions.  As you continue to work with @command{lily-git.tcl}, the
106 @qq{Update source} button will take any new additions and add it
107 to whatever is currently in your repository's history.
108 @end quotation
109
110
111 @node Daily use of lily-git.tcl
112 @unnumberedsubsec Daily use of @command{lily-git.tcl}
113
114 @warning{Only work on one set of changes at once.  Do not start
115 work on any new changes until your first set has been accepted.}
116
117 @subsubheading 1. Update source
118
119 At the beginning of each session of lilypond work, you should
120 click the @qq{Update source} button to get the latest changes to
121 the source code.
122
123 @warning{In some rare and unfortunate circumstances, this will
124 result in a @emph{merge conflict}.  If this occurs, follow the
125 instructions for @qq{Abort changes}, below.  Your work will not be
126 lost.}
127
128
129 @subsubheading 2a. New local commit
130
131 A single commit typically represents one logical set of related
132 changes (such as a bug-fix), and may incorporate changes to
133 multiple files at the same time.
134
135 When you're finished making the changes for a commit, click the
136 @qq{New local commit} button.  This will open the @qq{Git Commit
137 Message} window.  The message header is required, and the message
138 body is optional.
139
140 After entering a commit message, click @qq{OK} to finalize the
141 commit.
142
143 @quotation
144 Advanced note: For more information regarding commits and commit
145 messages, see @ref{Commits and patches}.
146 @end quotation
147
148
149 @subsubheading 2b. Amend previous commit
150
151 You can go back and make changes to the most recent commit with
152 the @qq{Amend previous commit} button.  This is useful if a
153 mistake is found after you have clicked the @qq{New local commit}
154 button.
155
156 To amend the most recent commit, re-edit the source files as
157 needed and then click the @qq{Amend previous commit} button.  The
158 earlier version of the commit is not saved, but is replaced by the
159 new one.
160
161 @warning{This does not update the patch @strong{files}; if you
162 have a patch file from an earlier version of the commit, you will
163 need to make another patch set when using this feature.  The old
164 patch file will not be saved, but will be replaced by the new one
165 after you click on @qq{Make patch set}.}
166
167
168 @subsubheading 3. Make patch set
169
170 Before making a patch set from any commits, you should click the
171 @qq{Update source} button to make sure the commits are based on
172 the most recent remote snapshot.
173
174 When you click the @qq{Make patch set} button,
175 @command{lily-git.tcl} will produce patch files for any new
176 commits, saving them to the current directory.  The command output
177 will display the name of the new patch files near the end of the
178 output:
179
180 @example
181 0001-CG-add-lily-git-instructions.patch
182 Done.
183 @end example
184
185 Send patch files to the appropriate place:
186
187 @itemize
188 @item
189 If you have a mentor, send it to them via email.
190
191 @item
192 New contributors should send the patch attached to an email to
193 @email{frogs@@lilynet.net}.  Please add @qq{[PATCH]} to the
194 subject line.
195
196 @item
197 Translators should send patches to
198 @email{translations@@lilynet.net}.
199
200 @item
201 More experienced contributors should upload the patch for
202 web-based review.  This requires additional software and use of
203 the command-line; see @ref{Uploading a patch for review}.
204
205 @end itemize
206
207
208 @subsubheading The @qq{Abort changes -- Reset to origin} button
209
210 @warning{Only use this if your local commit history gets
211 hopelessly confused!}
212
213 The button labeled @qq{Abort changes -- Reset to origin} will copy
214 all changed files to a subdirectory of @file{lilypond-git/} named
215 @file{aborted_edits/}, and will reset the repository to the
216 current state of the remote repository (at @code{git.sv.gnu.org}).
217
218
219 @node Starting with Git
220 @section Starting with Git
221
222
223 Using the Git program directly (as opposed to using the
224 @command{lily-git.tcl} GUI) allows you to have much greater control
225 over the contributing process.  You should consider using Git if
226 you want to work on complex projects, or if you want to work on
227 multiple projects concurrently.
228
229
230 @menu
231 * Setting up::
232 * Downloading remote branches::
233 @end menu
234
235
236 @node Setting up
237 @subsection Setting up
238
239
240 TODO: Remove this note if incorporating Windows instructions
241 throughout this section:
242
243 @warning{These instructions assume that you are using the
244 command-line version of Git 1.5 or higher.  Windows users should
245 skip to @ref{Git on Windows}.}
246
247 @menu
248 * Installing Git::
249 * Initializing a repository::
250 * Configuring Git::
251 @end menu
252
253
254 @node Installing Git
255 @unnumberedsubsubsec Installing Git
256
257
258 If you are using a Unix-based machine, the easiest way to download
259 and install Git is through a package manager such as @command{rpm}
260 or @command{apt-get}---the installation is generally automatic.
261 The only required package is (usually) called @command{git-core},
262 although some of the auxiliary @command{git@var{*}} packages are
263 also useful (such as @command{gitk}).
264
265 Alternatively, you can visit the Git website
266 (@uref{http://git-scm.com/}) for downloadable binaries and
267 tarballs.
268
269 TODO: add Windows installation instructions (or @@ref@{Git on
270 Windows@}).
271
272
273 @node Initializing a repository
274 @unnumberedsubsubsec Initializing a repository
275
276
277 Once Git is installed, you'll need to create a new directory where
278 your initial repository will be stored (the example below uses
279 @file{~/lilypond-git/}, where @code{~} represents your home
280 directory).  Run @command{git@tie{}init} from within the new
281 directory to initialize an empty repository:
282
283 @example
284 mkdir ~/lilypond-git/; cd ~/lilypond-git/
285 git init
286 @end example
287
288 @subsubheading Technical details
289
290 This creates (within the @file{~/lilypond-git/} directory) a
291 subdirectory called @file{.git/}, which Git uses to keep track of
292 changes to the repository, among other things.  Normally you don't
293 need to access it, but it's good to know it's there.
294
295
296 @node Configuring Git
297 @unnumberedsubsubsec Configuring Git
298
299 @warning{Throughout the rest of this manual, all command-line
300 input should be entered from the top directory of the Git
301 repository being discussed (eg. @file{~/lilypond-git/}).  This is
302 referred to as a @emph{top source directory}.}
303
304 Before downloading a copy of the main LilyPond repository, you
305 should configure some basic settings with the
306 @command{git@tie{}config} command.  Git allows you to set both
307 global and repository-specific options.
308
309 To configure settings that affect all repositories, use the
310 @command{--global} command line option.  For example, the first
311 two options that you should always set are your @var{name} and
312 @var{email}, since Git needs these to keep track of commit
313 authors:
314
315 @example
316 git config --global user.name "@var{John Smith}"
317 git config --global user.email @var{john@@example.com}
318 @end example
319
320 To configure Git to use colored output where possible, use:
321
322 @example
323 git config --global color.ui auto
324 @end example
325
326 The text editor that opens when using @command{git@tie{}commit}
327 can also be changed.  If none of your editor-related environment
328 variables are set ($GIT_EDITOR, $VISUAL, or $EDITOR), the default
329 editor is usually @command{vi} or @command{vim}.  If you're not
330 familiar with either of these, you should probably change the
331 default to an editor that you know how to use.  For example, to
332 change the default editor to @command{nano}, enter:
333
334 @example
335 git config --global core.editor @var{nano}
336 @end example
337
338 TODO: Add instructions for changing the editor on Windows, which
339 is a little different, I think. -mp
340
341 @subsubheading Technical details
342
343 Git stores the information entered with
344 @command{git@tie{}config@tie{}--global} in the file
345 @file{.gitconfig}, located in your home directory.  This file can
346 also be modified directly, without using
347 @command{git@tie{}config}.  The @file{.gitconfig} file generated
348 by the above commands would look like this:
349
350 @example
351 [user]
352         name = John Smith
353         email = john@@example.com
354 [color]
355         ui = auto
356 [core]
357         editor = nano
358 @end example
359
360 Using the @command{git@tie{}config} command @emph{without} the
361 @command{--global} option configures repository-specific settings,
362 which are stored in the file @file{.git/config}.  This file is
363 created when a repository is initialized (using
364 @command{git@tie{}init}), and by default contains these lines:
365
366 @example
367 [core]
368         repositoryformatversion = 0
369         filemode = true
370         bare = false
371         logallrefupdates = true
372 @end example
373
374 However, since different repository-specific options are
375 recommended for different development tasks, it is best to avoid
376 setting any now.  Specific recommendations will be mentioned later
377 in this manual.
378
379
380 @node Downloading remote branches
381 @subsection Downloading remote branches
382
383
384 @menu
385 * Organization of remote branches::
386 * LilyPond repository sources::
387 * Downloading individual branches::
388 * Downloading all remote branches::
389 * Other branches::
390 @end menu
391
392
393 @node Organization of remote branches
394 @unnumberedsubsubsec Organization of remote branches
395
396
397 The main LilyPond repository is organized into @emph{branches} to
398 facilitate development.  These are often called @emph{remote}
399 branches to distinguish them from @emph{local} branches you might
400 create yourself (see @ref{Using local branches}).
401
402 The @code{master} branch contains all the source files used to
403 build LilyPond, which includes the program itself (both stable and
404 development releases), the documentation (and its translations),
405 and the website.  Generally, the @code{master} branch is expected
406 to compile successfully.
407
408 The @code{lilypond/translation} branch is a side branch that
409 allows translators to work without needing to worry about
410 compilation problems.  Periodically, the Translation Meister
411 (after verifying that it doesn't break compilation), will
412 @emph{merge} this branch back into @code{master} to incorporate
413 recent translations.  Similarly, the @code{master} branch is
414 usually merged into the @code{lilypond/translation} branch after
415 significant changes to the English documentation.  See
416 @ref{Translating the documentation} for details.
417
418
419 @node LilyPond repository sources
420 @unnumberedsubsubsec LilyPond repository sources
421
422
423 The recommended source for downloading a copy of the main
424 repository is:
425
426 @example
427 git://git.sv.gnu.org/lilypond.git
428 @end example
429
430 However, if your internet router filters out connections using the
431 GIT protocol, or if you experience difficulty connecting via GIT,
432 you can try these other sources:
433
434 @example
435 ssh://git.sv.gnu.org/srv/git/lilypond.git
436 http://git.sv.gnu.org/r/lilypond.git
437 @end example
438
439 The SSH protocol can only be used if your system is properly set
440 up to use it.  Also, the HTTP protocol is slowest, so it should
441 only be used as a last resort.
442
443
444 @node Downloading individual branches
445 @unnumberedsubsubsec Downloading individual branches
446
447
448 Once you have initialized an empty Git repository on your system
449 (see @ref{Initializing a repository}), you can download a remote
450 branch into it.  Make sure you know which branch you want to start
451 with.
452
453 To download the @code{master} branch, enter the following:
454
455 @example
456 git remote add -ft master -m master \
457   origin git://git.sv.gnu.org/lilypond.git/
458 @end example
459
460 To download the @code{lilypond/translation} branch, enter:
461
462 @example
463 git remote add -ft lilypond/translation -m \
464   lilypond/translation origin git://git.sv.gnu.org/lilypond.git/
465 @end example
466
467 The @command{git@tie{}remote@tie{}add} process could take up to
468 ten minutes, depending on the speed of your connection.  The
469 output will be something like this:
470
471 @example
472 Updating origin
473 remote: Counting objects: 235967, done.
474 remote: Compressing objects: 100% (42721/42721), done.
475 remote: Total 235967 (delta 195098), reused 233311 (delta 192772)
476 Receiving objects: 100% (235967/235967), 68.37 MiB | 479 KiB/s, done.
477 Resolving deltas: 100% (195098/195098), done.
478 From git://git.sv.gnu.org/lilypond
479  * [new branch]      master     -> origin/master
480 From git://git.sv.gnu.org/lilypond
481  * [new tag]         flower/1.0.1 -> flower/1.0.1
482  * [new tag]         flower/1.0.10 -> flower/1.0.10
483 â‹®
484  * [new tag]         release/2.9.6 -> release/2.9.6
485  * [new tag]         release/2.9.7 -> release/2.9.7
486 @end example
487
488 When @command{git@tie{}remote@tie{}add} is finished, the remote
489 branch should be downloaded into your repository---though not yet
490 in a form that you can use.  In order to browse the source code
491 files, you need to @emph{create} and @emph{checkout} your own
492 local branch.  In this case, however, it is easier to have Git
493 create the branch automatically by using the @command{checkout}
494 command on a non-existent branch.  Enter the following:
495
496 @example
497 git checkout -b @var{branch} origin/@var{branch}
498 @end example
499
500 @noindent
501 where @code{@var{branch}} is the name of your tracking branch,
502 either @code{master} or @code{lilypond/translation}.
503
504 Git will issue some warnings; this is normal:
505
506 @example
507 warning: You appear to be on a branch yet to be born.
508 warning: Forcing checkout of origin/master.
509 Branch master set up to track remote branch master from origin.
510 Already on 'master'
511 @end example
512
513 By now the source files should be accessible---you should be able
514 to edit any files in the @file{lilypond-git/} directory using a
515 text editor of your choice.  But don't start just yet!  Before
516 editing any source files, learn how to keep your changes organized
517 and prevent problems later---read @ref{Basic Git procedures}.
518
519 @subsubheading Technical Details
520
521 The @command{git@tie{}remote@tie{}add} command should add some
522 lines to your local repository's @file{.git/config} file:
523
524 @example
525 [remote "origin"]
526         url = git://git.sv.gnu.org/lilypond.git/
527         fetch = +refs/heads/master:refs/remotes/origin/master
528 @end example
529
530
531 @node Downloading all remote branches
532 @unnumberedsubsubsec Downloading all remote branches
533
534
535 To download all remote branches at once, you can @command{clone}
536 the entire repository:
537
538 @example
539 git clone git://git.sv.gnu.org/lilypond.git
540 @end example
541
542
543 @node Other branches
544 @unnumberedsubsubsec Other branches
545
546 Most contributors will never need to touch the other branches.  If
547 you wish to do so, you will need more familiarity with Git; please
548 see @ref{Other Git documentation}.
549
550 @itemize
551 @item @code{dev/XYZ}:
552 These branches are for individual developers.  They store code
553 which is not yet stable enough to be added to the @code{master}
554 branch.
555
556 @item @code{stable/XYZ}:
557 The branches are kept for archival reasons.
558
559 @end itemize
560
561 Another item of interest might be the Grand Unified Builder, our
562 cross-platform building tool.  Since it is used by projects as
563 well, it is not stored in our gub repository.  For more info, see
564 @uref{http://lilypond.org/gub}.  The git location is
565 @uref{http://github.com/janneke/gub}.
566
567
568 @node Basic Git procedures
569 @section Basic Git procedures
570
571
572 @menu
573 * The Git contributor's cycle::
574 * Pulling and rebasing::
575 * Using local branches::
576 * Commits and patches::
577 @end menu
578
579
580 @node The Git contributor's cycle
581 @subsection The Git contributor's cycle
582
583
584 Here is a simplified view of the contribution process on Git:
585
586 @enumerate
587 @item
588 Update your local repository by @emph{pulling} the most recent
589 updates from the remote repository.
590
591 @item
592 Edit source files within your local repository's @emph{working
593 directory}.
594
595 @item
596 @emph{Commit} the changes you've made to a local @emph{branch}.
597
598 @item
599 Generate a @emph{patch} to share your changes with the developers.
600 @end enumerate
601
602
603 @node Pulling and rebasing
604 @subsection Pulling and rebasing
605
606
607 When developers push new patches to the @code{git.sv.gnu.org}
608 repository, your local repository is @strong{not} automatically
609 updated.  It is important to keep your repository up-to-date by
610 periodically @emph{pulling} the most recent @emph{commits} from
611 the remote branch.  Developers expect patches to be as current as
612 possible, since outdated patches require extra work before they
613 can be used.
614
615 Occasionally you may need to rework some of your own modifications
616 to match changes made to the remote branch (see @ref{Resolving
617 conflicts}), and it's considerably easier to rework things
618 incrementally.  If you don't update your repository along the way,
619 you may have to spend a lot of time resolving branch conflicts and
620 reconfiguring much of the work you've already done.
621
622 Fortunately, Git is able to resolve certain types of branch
623 conflicts automatically with a process called @emph{rebasing}.
624 When rebasing, Git tries to modify your old commits so they appear
625 as new commits (based on the latest updates).  For a more involved
626 explanation, see the @command{git-rebase} man page.
627
628 To pull without rebasing (recommended for translators), use the
629 following command:
630
631 @example
632 git pull    # recommended for translators
633 @end example
634
635 If you're tracking the remote @code{master} branch, you should add
636 the @code{-r} option (short for @code{--rebase}) to keep commits
637 on your local branch current:
638
639 @example
640 git pull -r # use with caution when translating
641 @end example
642
643 If you don't edit translated documentation and don't want to type
644 @code{-r} every time, configure the master branch to rebase by
645 default with this command:
646
647 @example
648 git config branch.master.rebase true
649 @end example
650
651 If pull fails because of a message like
652
653 @example
654 error: Your local changes to 'Documentation/learning/tutorial.itely'
655 would be overwritten by merge.  Aborting.
656 @end example
657
658 @noindent
659 or
660
661 @example
662 Documentation/learning/tutorial.itely: needs update
663 refusing to pull with rebase: your working tree is not up-to-date
664 @end example
665
666 @noindent
667 it means that you have modified some files in you working tree
668 without committing changes (see @ref{Commits and patches}); you
669 can use the @command{git@tie{}stash} command to work around this:
670
671 @example
672 git stash      # save uncommitted changes
673 git pull -r    # pull using rebase (translators omit "-r")
674 git stash pop  # reapply previously saved changes
675 @end example
676
677 Note that @command{git@tie{}stash@tie{}pop} will try to apply a
678 patch, and this may create a conflict.  If this happens, see
679 @ref{Resolving conflicts}.
680
681 TODO: I think the next paragraph is confusing.  Perhaps prepare
682 the reader for new terms `committish' and `head'?  -mp
683
684 @warning{translators and documentation editors, if you have
685 changed committishes in the head of translated files using commits
686 you have not yet pushed to @code{git.sv.gnu.org}, please do not
687 rebase.  If you want to avoid wondering whether you should rebase
688 each time you pull, please always use committishes from master
689 and/or lilypond/translation branch on @code{git.sv.gnu.org}, which
690 in particular implies that you must push your changes to
691 documentation except committishes updates (possibly after having
692 rebased), then update the committishes and push them.}
693
694 TODO: when committishes automatic conditional update have been
695 tested and documented, append the following to the warning above:
696 Note that using update-committishes make target generally touches
697 committishes.
698
699 @subsubheading Technical details
700
701 The @command{git@tie{}config} command mentioned above adds the
702 line @code{rebase = true} to the master branch in your local
703 repository's @file{.git/config} file:
704
705 @example
706 [branch "master"]
707         remote = origin
708         merge = refs/heads/master
709         rebase = true
710 @end example
711
712
713 @node Using local branches
714 @subsection Using local branches
715
716
717 @menu
718 * Creating and removing branches::
719 * Listing branches and remotes::
720 * Checking out branches::
721 * Merging branches::
722 @end menu
723
724
725 @node Creating and removing branches
726 @unnumberedsubsubsec Creating and removing branches
727
728
729 Local branches are useful when you're working on several different
730 projects concurrently.  To create a new branch, enter:
731
732 @example
733 git branch @var{name}
734 @end example
735
736 To delete a branch, enter:
737
738 @example
739 git branch -d @var{name}
740 @end example
741
742 Git will ask you for confirmation if it sees that data would be
743 lost by deleting the branch.  Use @code{-D} instead of @code{-d}
744 to bypass this.  Note that you cannot delete a branch if it is
745 currently checked out.
746
747
748 @node Listing branches and remotes
749 @unnumberedsubsubsec Listing branches and remotes
750
751 You can get the exact path or URL of all remote branches by
752 running:
753
754 @example
755 git remote -v
756 @end example
757
758 To list Git branches on your local repositories, run
759
760 @example
761 git branch     # list local branches only
762 git branch -r  # list remote branches
763 git branch -a  # list all branches
764 @end example
765
766
767 @node Checking out branches
768 @unnumberedsubsubsec Checking out branches
769
770 To know the currently checked out branch, i.e. the branch whose
771 source files are present in your working tree, read the first line
772 of the output of
773
774 @example
775 git status
776 @end example
777
778 @noindent
779 The currently checked out branch is also marked with an asterisk
780 in the output of @command{git branch}.
781
782 You can check out another branch @code{@var{other_branch}}, i.e.
783 check out @code{@var{other_branch}} to the working tree, by
784 running
785
786 @example
787 git checkout @var{other_branch}
788 @end example
789
790 Note that it is possible to check out another branch while having
791 uncommitted changes, but it is not recommended unless you know
792 what you are doing; it is recommended to run @command{git status}
793 to check this kind of issue before checking out another branch.
794
795 @node Merging branches
796 @unnumberedsubsubsec Merging branches
797
798 To merge branch @code{@var{foo}} into branch @code{@var{bar}},
799 i.e. to @qq{add} all changes made in branch @code{@var{foo}} to
800 branch @code{@var{bar}}, run
801
802 @example
803 git checkout @var{bar}
804 git merge @var{foo}
805 @end example
806
807 If any conflict happens, see @ref{Resolving conflicts}.
808
809 There are common usage cases for merging: as a translator, you
810 will often want to merge @code{master} into
811 @code{lilypond/translation}; on the other hand, the Translations
812 meister wants to merge @code{lilypond/translation} into
813 @code{master} whenever he has checked that
814 @code{lilypond/translation} builds successfully.
815
816
817 @node Commits and patches
818 @subsection Commits and patches
819
820
821 @menu
822 * Understanding commits::
823 * Making commits::
824 * Commit messages::
825 * Making patches::
826 * Uploading a patch for review::
827 @end menu
828
829
830 @node Understanding commits
831 @unnumberedsubsubsec Understanding commits
832
833 Technically, a @emph{commit} is a single point in the history of a
834 branch, but most developers use the term to mean a @emph{commit
835 object}, which stores information about a particular revision.  A
836 single commit can record changes to multiple source files, and
837 typically represents one logical set of related changes (such as a
838 bug-fix).  You can list the ten most recent commits in your
839 current branch with this command:
840
841 @example
842 git log -10 --oneline
843 @end example
844
845 If you're using an older version of Git and get an @q{unrecognized
846 argument} error, use this instead:
847
848 @example
849 git log -10 --pretty=oneline --abbrev-commit
850 @end example
851
852 More interactive lists of the commits on the remote @code{master}
853 branch are available at
854 @uref{http://git.sv.gnu.org/gitweb/?p=lilypond.git;a=shortlog} and
855 @uref{http://git.sv.gnu.org/cgit/lilypond.git/log/}.
856
857
858 @node Making commits
859 @unnumberedsubsubsec Making commits
860
861
862 Once you have modified some source files in your working
863 directory, you can make a commit with the following procedure:
864
865 @enumerate
866 @item
867 Make sure you've configured Git properly (see @ref{Configuring
868 Git}).  Check that your changes meet the requirements described in
869 @ref{Code style} and/or @ref{Documentation policy}.  For advanced
870 edits, you may also want to verify that the changes don't break
871 the compilation process.
872
873 @item
874 Run the following command:
875
876 @example
877 git status
878 @end example
879
880 @noindent
881 to make sure you're on the right branch, and to see which files
882 have been modified, added or removed, etc.  You may need to tell
883 Git about any files you've added by running one of these:
884
885 @example
886 git add @var{file}  # add untracked @var{file} individually
887 git add .     # add all untracked files in current directory
888 @end example
889
890 @noindent
891 After @command{git@tie{}add}, run @command{git@tie{}status} again
892 to make sure you got everything.  You may also need to modify
893 @file{GNUmakefile}.
894
895 @item
896 Preview the changes about to be committed (to make sure everything
897 looks right) with:
898
899 @example
900 git diff HEAD
901 @end example
902
903 @noindent
904 The @code{HEAD} argument refers to the most recent commit on the
905 currently checked-out branch.
906
907 @item
908 Generate the commit with:
909
910 @example
911 git commit -a
912 @end example
913
914 @noindent
915 The @code{-a} is short for @code{--all} which includes modified
916 and deleted files, but only those newly created files that have
917 previously been added.
918
919 @end enumerate
920
921
922 @node Commit messages
923 @unnumberedsubsubsec Commit messages
924
925
926 When you run the @command{git@tie{}commit@tie{}-a} command, Git
927 automatically opens the default text editor so you can enter a
928 @emph{commit message}.  If you find yourself in a foreign editing
929 environment, you're probably in @command{vi} or @command{vim}.  If
930 you want to switch to an editor you're more familiar with, quit by
931 typing @code{:q!} and pressing @code{<Enter>}.  See
932 @ref{Configuring Git} for instructions on changing the default
933 editor.
934
935 In any case, Git will open a text file for your commit message
936 that looks like this:
937
938 @example
939
940 # Please enter the commit message for your changes.  Lines starting
941 # with '#' will be ignored, and an empty message aborts the commit.
942 # On branch master
943 # Changes to be committed:
944 #   (use "git reset HEAD <file>..." to unstage)
945 #
946 #       modified:   working.itexi
947 #
948 @end example
949
950 Your commit message should begin with a one-line summary
951 describing the change (no more than 50 characters long), and if
952 necessary a blank line followed by several lines giving the
953 details:
954
955 @c $ git log -1 --pretty=medium 4d6f1e5
956 @example
957 Doc: add Baerenreiter and Henle solo cello suites
958
959 Added comparison of solo cello suite engravings to new essay with
960 high-res images, fixed cropping on Finale example.
961 @end example
962
963 Commit messages often start with a short prefix describing the
964 general location of the changes.  If a commit affects the
965 documentation in English (or in several languages simultaneously)
966 the commit message should be prefixed with @qq{Doc:@tie{}}.  If
967 the commit affects only one of the translations, the commit
968 message should be prefixed with @qq{Doc-@var{**}:@tie{}}, where
969 @var{**} is the two-letter language code.  Commits that affect the
970 website should use @qq{Web:@tie{}} for English, and
971 @qq{Web-@var{**}:@tie{}} for the other languages.  Also, changes
972 to a single file are often prefixed with the name of the file
973 involved.  Visit the links listed in @ref{Understanding commits}
974 for examples.
975
976
977 @node Making patches
978 @unnumberedsubsubsec Making patches
979
980 If you want to share your changes with other contributors and
981 developers, you need to generate @emph{patches} from your commits.
982 We prefer it if you follow the instructions in
983 @ref{Uploading a patch for review}.  However, we present an
984 alternate method here.
985
986 You should always run @command{git@tie{}pull@tie{}-r} (translators
987 should leave off the @code{-r}) before doing this to ensure that
988 your patches are as current as possible.
989
990 Once you have made one or more commits in your local repository,
991 and pulled the most recent commits from the remote branch, you can
992 generate patches from your local commits with the command:
993
994 @example
995 git format-patch origin
996 @end example
997
998 The @code{origin} argument refers to the remote tracking branch at
999 @code{git.sv.gnu.org}.  This command generates a separate patch
1000 for each commit that's in the current branch but not in the remote
1001 branch.  Patches are placed in the current working directory and
1002 will have names that look something like this:
1003
1004 @example
1005 0001-Doc-Fix-typos.patch
1006 0002-Web-Remove-dead-links.patch
1007 â‹®
1008 @end example
1009
1010 Send an email (must be less than 64 KB) to
1011 @email{lilypond-devel@@gnu.org} briefly explaining your work, with
1012 the patch files attached.  Translators should send patches to
1013 @email{translations@@lilynet.net}.  After your patches are
1014 reviewed, the developers may push one or more of them to the main
1015 repository or discuss them with you.
1016
1017
1018 @node Uploading a patch for review
1019 @unnumberedsubsubsec Uploading a patch for review
1020
1021 Any non-trivial change should be uploaded to our @qq{Rietveld}
1022 code review website:
1023
1024 @example
1025 @uref{http://codereview.appspot.com/}
1026 @end example
1027
1028 @subsubheading Initial setup
1029
1030 @enumerate
1031
1032 @item
1033 You must have a gmail account.
1034
1035 @item
1036 Install @command{git-cl} by entering:
1037
1038 @example
1039 git clone git://neugierig.org/git-cl.git
1040 @end example
1041
1042 @item
1043 Add the @file{git-cl/} directory to your PATH, or create a
1044 symbolic link to the @command{git-cl} and @command{upload.py}
1045 scripts in one of your PATH directories (such as
1046 @file{$HOME/bin}).
1047
1048
1049 @item
1050 Move into the top source directory and then configure
1051 @command{git cl}.  If you do not understand any question, just
1052 answer with a newline (CR).
1053
1054 @example
1055 cd $HOME/lilypond-git/
1056 git cl config
1057 @end example
1058
1059 The @qq{CC list} question should be answered with:
1060
1061 @example
1062 lilypond-devel@@gnu.org
1063 @end example
1064
1065 @end enumerate
1066
1067 @subsubheading Uploading patch set
1068
1069 @warning{Unless you are familiar with branches, only work on one
1070 set of changes at once.}
1071
1072 There are two methods, depending on your git setup.
1073
1074 @itemize
1075 @item
1076 @strong{Master branch}: (easy option, and used in @command{lily-git.tcl})
1077
1078 If you added your patch to @code{master}, then:
1079
1080 @example
1081 git pull -r
1082 git cl upload origin/master
1083 @end example
1084
1085 If you have git push ability, make sure that you @emph{remove}
1086 your patch (with @command{git rebase} or @command{git reset})
1087 before pushing other stuff.
1088
1089 @item
1090 @strong{Separate branch}: (complicated option)
1091
1092 Ensure your changes are committed in a separate branch, which
1093 should differ from the reference branch to be used by just the
1094 changes to be uploaded.  If the reference branch is to be
1095 origin/master, ensure this is up-to-date.  If necessary, use git
1096 rebase to rebase the branch containing the changes to the head of
1097 origin/master.  Finally, check out branch with the changes and
1098 enter the command:
1099
1100 @example
1101 git cl upload <reference SHA1 ID>
1102 @end example
1103
1104 @noindent
1105 where <reference SHA1 ID> is the SHA1 ID of the commit to be used
1106 as a reference source for the patch.  Generally, this will be the
1107 SHA1 ID of origin/master, and in that case the command:
1108
1109 @example
1110 git cl upload origin/master
1111 @end example
1112
1113 @noindent
1114 can be used.
1115
1116 @end itemize
1117
1118 After prompting for your Google email address and password, the
1119 patch set will be posted to Rietveld, and you will be given a URL
1120 for your patch.
1121
1122 @subsubheading Announcing your patch set
1123
1124 You should then announce the patch by logging into the code review
1125 issue webpage and using @qq{Publish + Mail Comments} to add a
1126 (mostly bogus) comment to your issue.  The text of your comment
1127 will be sent to our developer mailing list.
1128
1129 @subsubheading Revisions
1130
1131 As revisions are made in response to comments, successive patch sets
1132 for the same issue can be uploaded by reissuing the git-cl command
1133 with the modified branch checked out.
1134
1135 Sometimes in response to comments on revisions, the best way to
1136 work may require creation of a new branch in git.  In order to
1137 associate the new branch with an existing Rietveld issue,
1138 the following command can be used:
1139
1140 @example
1141 git cl issue issue-number
1142 @end example
1143
1144 @noindent
1145 where @code{issue-number} is the number of the existing Rietveld
1146 issue.
1147
1148 @subsubheading Resetting git cl
1149
1150 If @command{git cl} becomes confused, you can @qq{reset} it by
1151 running:
1152
1153 @example
1154 git cl issue 0
1155 @end example
1156
1157
1158 @node Advanced Git procedures
1159 @section Advanced Git procedures
1160
1161
1162 @warning{This section is not necessary for normal contributors;
1163 these commands are presented for information for people interested
1164 in learning more about git.}
1165
1166 It is possible to work with several branches on the same local Git
1167 repository; this is especially useful for translators who may have
1168 to deal with both @code{lilypond/translation} and a stable branch,
1169 e.g. @code{stable/2.12}.
1170
1171 Some Git commands are introduced first, then a workflow with
1172 several Git branches of LilyPond source code is presented.
1173
1174
1175 @menu
1176 * Advanced Git concepts::
1177 * Resolving conflicts::
1178 * Reverting all local changes::
1179 * Working with remote branches::
1180 * Git log::
1181 * Applying remote patches::
1182 * Sending and receiving patches via email::
1183 * Commit access::
1184 @end menu
1185
1186
1187 @node Advanced Git concepts
1188 @subsection Advanced Git concepts
1189
1190
1191 A bit of Git vocabulary will be explained below.  The following is
1192 only introductory; for a better understanding of Git concepts, you
1193 may wish to read @ref{Other Git documentation}.
1194
1195 The @code{git@tie{}pull@tie{}origin} command above is just a
1196 shortcut for this command:
1197
1198 @example
1199 git pull git://git.sv.gnu.org/lilypond.git/ @var{branch}:origin/@var{branch}
1200 @end example
1201
1202 @noindent
1203 where @code{@var{branch}} is typically @code{master} or
1204 @code{lilypond/translation}; if you do not know or remember, see
1205 @ref{Downloading remote branches} to remember which commands you
1206 issued or which source code you wanted to get.
1207
1208 A @emph{commit} is a set of changes made to the sources; it also
1209 includes the committish of the parent commit, the name and e-mail
1210 of the @emph{author} (the person who wrote the changes), the name
1211 and e-mail of the @emph{committer} (the person who brings these
1212 changes into the Git repository), and a commit message.
1213
1214 A @emph{committish} is the SHA1 checksum of a commit, a number
1215 made of 40 hexadecimal digits, which acts as the internal unique
1216 identifier for this commit.  To refer to a particular revision,
1217 don't use vague references like the (approximative) date, simply
1218 copy and paste the committish.
1219
1220 A @emph{branch} is nothing more than a pointer to a particular
1221 commit, which is called the @emph{head} of the branch; when
1222 referring to a branch, one often actually thinks about its head
1223 and the ancestor commits of the head.
1224
1225 Now we will explain the two last commands you used to get the
1226 source code from Git---see @ref{Downloading individual branches}.
1227
1228 @example
1229 git remote add -ft @var{branch} -m @var{branch} \
1230   origin git://git.sv.gnu.org/lilypond.git/
1231
1232 git checkout -b @var{branch} origin/@var{branch}
1233 @end example
1234
1235 The @command{git@tie{}remote} has created a branch called
1236 @code{origin/@var{branch}} in your local Git repository.  As this
1237 branch is a copy of the remote branch web from git.sv.gnu.org
1238 LilyPond repository, it is called a @emph{remote branch}, and is
1239 meant to track the changes on the branch from git.sv.gnu.org: it
1240 will be updated every time you run
1241 @command{git@tie{}pull@tie{}origin} or
1242 @command{git@tie{}fetch@tie{}origin}.
1243
1244 The @command{git@tie{}checkout} command has created a branch named
1245 @code{@var{branch}}.  At the beginning, this branch is identical
1246 to @code{origin/@var{branch}}, but it will differ as soon as you
1247 make changes, e.g. adding newly translated pages or editing some
1248 documentation or code source file.  Whenever you pull, you merge
1249 the changes from @code{origin/@var{branch}} and
1250 @code{@var{branch}} since the last pulling.  If you do not have
1251 push (i.e. @qq{write}) access on git.sv.gnu.org, your
1252 @code{@var{branch}} will always differ from
1253 @code{origin/@var{branch}}.  In this case, remember that other
1254 people working like you with the remote branch @code{@var{branch}}
1255 of git://git.sv.gnu.org/lilypond.git/ (called
1256 @code{origin/@var{branch}} on your local repository) know nothing
1257 about your own @code{@var{branch}}: this means that whenever you
1258 use a committish or make a patch, others expect you to take the
1259 latest commit of @code{origin/@var{branch}} as a reference.
1260
1261 Finally, please remember to read the man page of every Git command
1262 you will find in this manual in case you want to discover
1263 alternate methods or just understand how it works.
1264
1265
1266 @node Resolving conflicts
1267 @subsection Resolving conflicts
1268
1269
1270 Occasionally an update may result in conflicts -- this happens
1271 when you and somebody else have modified the same part of the same
1272 file and git cannot figure out how to merge the two versions
1273 together.  When this happens, you must manually merge the two
1274 versions.
1275
1276 If you need some documentation to understand and resolve
1277 conflicts, see paragraphs @emph{How conflicts are presented} and
1278 @emph{How to resolve conflicts} in @command{git merge} man page.
1279
1280 If all else fails, you can follow the instructions in
1281 @ref{Reverting all local changes}.  Be aware that this eliminates
1282 any changes you have made!
1283
1284
1285 @node Reverting all local changes
1286 @subsection Reverting all local changes
1287
1288 Sometimes git will become hopelessly confused, and you just want
1289 to get back to a known, stable state.  This command destroys any
1290 local changes you have made, but at least you get back to the
1291 current online version:
1292
1293 @example
1294 git reset --hard origin/master
1295 @end example
1296
1297
1298 @node Working with remote branches
1299 @subsection Working with remote branches
1300
1301
1302 @subsubheading Fetching new branches from git.sv.gnu.org
1303
1304 To fetch and check out a new branch named @code{@var{branch}} on
1305 git.sv.gnu.org, run from top of the Git repository
1306
1307 @example
1308 git config --add remote.origin.fetch \
1309   +refs/heads/@var{branch}:refs/remotes/origin/@var{branch}
1310
1311 git checkout --track -b @var{branch} origin/@var{branch}
1312 @end example
1313
1314 After this, you can pull @code{@var{branch}} from git.sv.gnu.org
1315 with:
1316
1317 @example
1318 git pull
1319 @end example
1320
1321 Note that this command generally fetches all branches you added
1322 with @command{git@tie{}remote@tie{}add} (when you initialized the
1323 repository) or @command{git@tie{}config@tie{}--add}, i.e. it
1324 updates all remote branches from remote @code{origin}, then it
1325 merges the remote branch tracked by the current branch into the
1326 current branch.  For example, if your current branch is
1327 @code{master}, @code{origin/master} will be merged into
1328 @code{master}.
1329
1330
1331 @subsubheading Local clones, or having several working trees
1332
1333 If you play with several Git branches, e.g. @code{master},
1334 @code{lilypond/translation}, @code{stable/2.12}), you may want to
1335 have one source and build tree for each branch; this is possible
1336 with subdirectories of your local Git repository, used as local
1337 cloned subrepositories.  To create a local clone for the branch
1338 named @code{@var{branch}}, run
1339
1340 @example
1341 git checkout @var{branch}
1342 git clone -lsn . @var{subdir}
1343 cd @var{subdir}
1344 git reset --hard
1345 @end example
1346
1347 Note that @code{@var{subdir}} must be a directory name which does
1348 not already exist.  In @code{@var{subdir}}, you can use all Git
1349 commands to browse revisions history, commit and uncommit changes;
1350 to update the cloned subrepository with changes made on the main
1351 repository, cd into @code{@var{subdir}} and run
1352 @command{git@tie{}pull}; to send changes made on the subrepository
1353 back to the main repository, run @command{git@tie{}push} from
1354 @code{@var{subdir}}.  Note that only one branch (the currently
1355 checked out branch) is created in the subrepository by default; it
1356 is possible to have several branches in a subrepository and do
1357 usual operations (checkout, merge, create, delete...) on these
1358 branches, but this possibility is not detailed here.
1359
1360 When you push @code{@var{branch}} from @code{@var{subdir}} to the
1361 main repository, and @code{@var{branch}} is checked out in the
1362 main repository, you must save uncommitted changes (see
1363 @command{git@tie{}stash}) and do
1364 @command{git@tie{}reset@tie{}--hard} in the main repository in
1365 order to apply pushed changes in the working tree of the main
1366 repository.
1367
1368
1369 @node Git log
1370 @subsection Git log
1371
1372
1373 The commands above don't only bring you the latest version of the
1374 sources, but also the full history of revisions (revisions, also
1375 called commits, are changes made to the sources), stored in the
1376 @file{.git} directory.  You can browse this history with
1377
1378 @example
1379 git log     # only shows the logs (author, committish and commit message)
1380 git log -p  # also shows diffs
1381 gitk        # shows history graphically
1382 @end example
1383
1384 @warning{The @code{gitk} command may require a separate
1385 @code{gitk} package, available in the appropriate distribution's
1386 repositories.}
1387
1388
1389 @node Applying remote patches
1390 @subsection Applying remote patches
1391
1392
1393 TODO: Explain how to determine if a patch was created with
1394 @code{git@tie{}format-patch}.
1395
1396 Well-formed git patches created with @code{git@tie{}format-patch}
1397 should be committed with the following command:
1398
1399 @example
1400 git am @var{patch}
1401 @end example
1402
1403 Patches created without @code{git@tie{}format-patch} can be
1404 applied in two steps.  The first step is to apply the patch to the
1405 working tree:
1406
1407 @example
1408 git apply @var{patch}
1409 @end example
1410
1411 @noindent
1412 The second step is to commit the changes and give credit to the
1413 author of the patch.  This can be done with the following command:
1414
1415 @example
1416 git commit -a --author="@var{John Smith} <@var{john@@example.com}>"
1417 @end example
1418
1419
1420 @node Sending and receiving patches via email
1421 @subsection Sending and receiving patches via email
1422
1423
1424 The default @code{x-diff} MIME type associated with patch files
1425 (i.e., files whose name ends in @code{.patch}) means that the
1426 encoding of line endings may be changed from UNIX to DOS format
1427 when they are sent as attachments.  Attempting to apply such an
1428 inadvertently altered patch will cause git to fail with a message
1429 about @q{whitespace errors}.
1430
1431 The solution to such problems is surprisingly simple---just change
1432 the default file extension of patches generated by git to end in
1433 @code{.txt}, for example:
1434
1435 @example
1436 git config format.suffix '.patch.txt'
1437 @end example
1438
1439 This should cause email programs to apply the correct base64
1440 encoding to attached patches.
1441
1442 If you receive a patch with DOS instead of UNIX line-endings, it
1443 can be converted back using the @code{dos2unix} utility.
1444
1445 Lots of useful information on email complications with patches is
1446 provided on the Wine wiki at
1447 @uref{http://wiki.winehq.org/GitWine}.
1448
1449
1450 @node Commit access
1451 @subsection Commit access
1452
1453
1454 Most contributors are not able to commit patches directly to the
1455 main repository---only members of the LilyPond development team
1456 have @emph{commit access}.  If you are a contributor and are
1457 interested in joining the development team, contact the Project
1458 Manager through the mailing list
1459 (@email{lilypond-devel@@gnu.org}).  Generally, only contributors
1460 who have already provided a number of patches which have been
1461 pushed to the main repository will be considered for membership.
1462
1463 If you have been approved by the Project Manager, use the
1464 following procedure to obtain commit access:
1465
1466 @enumerate
1467 @item
1468 If you don't already have one, set up a Savannah user account at
1469 @uref{https://savannah.gnu.org/account/register.php}.  If your web
1470 browser responds with an @qq{untrusted connection} message when
1471 you visit the link, follow the steps for including the CAcert root
1472 certificate in your browser, given at
1473 @uref{http://savannah.gnu.org/tls/tutorial/}.
1474
1475
1476 @item
1477 After registering, if you are not logged in automatically, login
1478 at @uref{https://savannah.gnu.org/account/login.php}---this should
1479 take you to your @qq{my} page
1480 (@uref{https://savannah.gnu.org/my/}).
1481
1482
1483 @item
1484 Click on the @qq{My Groups} link to access the @qq{My Group
1485 Membership} page.  From there, find the @qq{Request for Inclusion}
1486 box and search for @qq{LilyPond}.  Among the search results, check
1487 the box labeled @qq{GNU LilyPond Music Typesetter} and write a
1488 brief (required) message for the Project Manager (@qq{Hey it's
1489 me!} should be fine).
1490
1491 Note that you will not have commit access until the Project
1492 Manager activates your membership.  Once your membership is
1493 activated, LilyPond should appear under the heading @qq{Groups I'm
1494 Contributor of} on your @qq{My Group Membership} page.
1495
1496
1497 @item
1498 Generate an SSH @q{dsa} key pair.  Enter the following at the
1499 command prompt:
1500
1501 @example
1502 ssh-keygen -t dsa
1503 @end example
1504
1505 When prompted for a location to save the key, press <ENTER> to
1506 accept the default location (@file{~/.ssh/id_dsa}).
1507
1508 Next you are asked to enter an optional passphrase.  On most
1509 systems, if you use a passphrase, you will likely be prompted for
1510 it every time you use @command{git@tie{}push} or
1511 @command{git@tie{}pull}.  You may prefer this since it can protect
1512 you from your own mistakes (like pushing when you mean to pull),
1513 though you may find it tedious to keep re-entering it.
1514
1515 You can change/enable/disable your passphrase at any time with:
1516
1517 @example
1518 ssh-keygen -f ~/.ssh/id_dsa -p
1519 @end example
1520
1521 Note that the GNOME desktop has a feature which stores your
1522 passphrase for you for an entire GNOME session.  If you use a
1523 passphrase to @qq{protect you from yourself}, you will want to
1524 disable this feature, since you'll only be prompted once.  Run the
1525 following command, then logout of GNOME and log back in:
1526
1527 @example
1528 gconftool-2 --set -t bool \
1529   /apps/gnome-keyring/daemon-components/ssh false
1530 @end example
1531
1532 After setting up your passphrase, your private key is saved as
1533 @file{~/.ssh/id_dsa} and your public key is saved as
1534 @file{~/.ssh/id_dsa.pub}.
1535
1536
1537 @item
1538 Register your public SSH @q{dsa} key with Savannah.  From the
1539 @qq{My Account Configuration} page, click on @qq{Edit SSH Keys},
1540 then paste the contents of your @file{~/.ssh/id_dsa.pub} file into
1541 one of the @qq{Authorized keys} text fields, and click
1542 @qq{Update}.
1543
1544 Savannah should respond with something like:
1545
1546 @example
1547 Success: Key #1 seen Keys registered
1548 @end example
1549
1550
1551 @item
1552 Configure Git to use the SSH protocol (instead of the GIT
1553 protocol).  From your local Git repository, enter:
1554
1555 @example
1556 git config remote.origin.url \
1557   ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
1558 @end example
1559
1560 @noindent
1561 where @var{user} is your username on Savannah.
1562
1563
1564 @item
1565 After your membership has been activated and you've configured Git
1566 to use SSH, test the connection with:
1567
1568 @example
1569 git pull --verbose
1570 @end example
1571
1572 SSH should issue the following warning:
1573
1574 @example
1575 The authenticity of host 'git.sv.gnu.org (140.186.70.72)' can't
1576 be established.
1577 RSA key fingerprint is
1578 80:5a:b0:0c:ec:93:66:29:49:7e:04:2b:fd:ba:2c:d5.
1579 Are you sure you want to continue connecting (yes/no)?
1580 @end example
1581
1582 Make sure the RSA key fingerprint displayed matches the one above.
1583 If it doesn't, respond @qq{no} and check that you configured Git
1584 properly in the previous step.  If it does match, respond
1585 @qq{yes}.  SSH should then issue another warning:
1586
1587 @example
1588 Warning: Permanently added 'git.sv.gnu.org,140.186.70.72' (RSA) to
1589 the list of known hosts.
1590 @end example
1591
1592 The list of known hosts is stored in the file
1593 @file{~/.ssh/known_hosts}.
1594
1595 At this point, you are prompted for your passphrase if you have
1596 one, then Git will attempt a pull.
1597
1598 If @command{git@tie{}pull@tie{}--verbose} fails, you should see
1599 error messages like these:
1600
1601 @example
1602 Permission denied (publickey).
1603 fatal: The remote end hung up unexpectedly
1604 @end example
1605
1606 If you get the above error, you may have made a mistake when
1607 registering your SSH key at Savannah.  If the key is properly
1608 registered, you probably just need to wait for the Savannah server
1609 to activate it.  It usually takes a few minutes for the key to be
1610 active after registering it, but if it still doesn't work after an
1611 hour, ask for help on the mailing list.
1612
1613 If @command{git@tie{}pull@tie{}--verbose} succeeds, the output
1614 will include a @q{From} line that shows @q{ssh} as the protocol:
1615
1616 @example
1617 From ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond
1618 @end example
1619
1620 If the protocol shown is not @q{ssh}, check that you configured
1621 Git properly in the previous step.
1622
1623
1624 @item
1625 Test your commit access with a dry run:
1626
1627 @example
1628 git push --dry-run --verbose
1629 @end example
1630
1631 Note that recent versions of Git (Git 1.6.3 or later) will issue a
1632 big warning if the above command is used.  The simplest solution
1633 is to tell Git to push all matching branches by default:
1634
1635 @example
1636 git config push.default matching
1637 @end example
1638
1639 @noindent
1640 Then @code{git@tie{}push} should work as before.  For more
1641 details, consult the @code{git@tie{}push} man page.
1642 @end enumerate
1643
1644
1645 @subsubheading Technical details
1646
1647 @itemize
1648 @item
1649 On Firefox, to view or remove the CAcert root certificate, go to:
1650 Edit > Preferences > Advanced > Encryption > View Certificates >
1651 Authorities > Certificate Name > Root CA > CA Cert Signing
1652 Authority.
1653
1654 @item
1655 The @command{git@tie{}config} commands above should modify your
1656 local repository's @file{.git/config} file.  These lines:
1657
1658 @example
1659 [remote "origin"]
1660         url = git://git.sv.gnu.org/lilypond.git/
1661 @end example
1662
1663 @noindent
1664 should now be changed to:
1665
1666 @example
1667 [remote "origin"]
1668         url = ssh://@var{user}@@git.sv.gnu.org/srv/git/lilypond.git
1669 @end example
1670
1671 @noindent
1672 where @var{user} is your login name on Savannah.
1673
1674 @item
1675 Similarly, the
1676 @command{git@tie{}config@tie{}push.default@tie{}matching} command
1677 should add these lines to @file{.git/config}:
1678
1679 @example
1680 [push]
1681         default = matching
1682 @end example
1683 @end itemize
1684
1685 @knownissues
1686 Encryption protocols, including ssh, generally do not permit packet
1687 fragmentation to avoid introducing a point of insecurity.  This
1688 means that the maximum packet size must not exceed the smallest
1689 MTU (Maximum Transmission Unit) set in the routers along the path.
1690 This smallest MTU is determined by a procedure during call set-up
1691 which relies on the transmission over the path of ICMP packets.
1692 If any of the routers in the path block ICMP packets this mechanism
1693 fails, resulting in the possibility of packets being transmitted
1694 which exceed the MTU of one of the routers.  If this happens the
1695 packet is discarded, causing the ssh session to hang, timeout or
1696 terminate with the error message
1697
1698 @example
1699 ssh: connect to host <host ip addr> port 22: Bad file number
1700 fatal: The remote end hung up unexpectedly
1701 @end example
1702
1703 depending on precisely when in the proceedings the first large
1704 packet is transmitted.  Most routers on the internet have MTU
1705 set to 1500, but routers installed in homes to connect via
1706 broadband may use a slightly smaller MTU for efficient transmission
1707 over ATM.  If this problem is encountered a possible work-around is
1708 to set the MTU in the local router to 1500.
1709
1710 @node Git on Windows
1711 @section Git on Windows
1712
1713 @c Some of this may duplicate stuff in other sections
1714 @c But it is probably best for windows users to have it all together
1715 @c If necessary, clear this up later  -td
1716
1717 TODO: Decide what to do with this...  Pare it down?  Move
1718 paragraphs next to analogous Unix instructions? -mp
1719
1720 @subsection Background to nomenclature
1721
1722 Git is a system for tracking the changes made to source files by a
1723 distributed set of editors.  It is designed to work without a
1724 master repository, but we have chosen to have a master repository
1725 for LilyPond files.  Editors hold a local copy of the master
1726 repository together with any changes they have made locally.
1727 Local changes are held in a local @q{branch}, of which there may
1728 be several, but these instructions assume you are using just one.
1729 The files visible in the local repository always correspond to
1730 those on the currently @q{checked out} local branch.
1731
1732 Files are edited on a local branch, and in that state the changes
1733 are said to be @q{unstaged}.  When editing is complete, the
1734 changes are moved to being @q{staged for commit}, and finally the
1735 changes are @q{committed} to the local branch.  Once committed,
1736 the changes (called a @q{commit}) are given a unique 40-digit
1737 hexadecimal reference number called the @q{Committish} or @q{SHA1
1738 ID} which identifies the commit to Git.  Such committed changes
1739 can be sent to the master repository by @q{pushing} them (if you
1740 have write permission) or by sending them by email to someone who
1741 has, either as a complete file or as a @q{diff} or @q{patch}
1742 (which send just the differences from the master repository).
1743
1744 @subsection Installing git
1745
1746 Obtain Git from
1747 @uref{http://code.google.com/p/msysgit/downloads/list} (note, not
1748 msysGit, which is for Git developers and not PortableGit, which is
1749 not a full git installation) and install it.
1750
1751 Note that most users will not need to install SSH.  That is not
1752 required until you have been granted direct push permissions to
1753 the master git repository.
1754
1755 Start Git by clicking on the desktop icon.  This will bring up a
1756 command line bash shell.  This may be unfamiliar to Windows users.
1757 If so, follow these instructions carefully.  Commands are entered
1758 at a $ prompt and are terminated by keying a newline.
1759
1760 @subsection Initialising Git
1761
1762 Decide where you wish to place your local Git repository, creating
1763 the folders in Windows as necessary.  Here we call the folder to
1764 contain the repository @code{[path]/Git}, but if you intend using
1765 Git for other projects a directory name like @code{lilypond-git}
1766 might be better.  You will need to have space for around
1767 100Mbytes.
1768
1769 Start the Git bash shell by clicking on the desk-top icon
1770 installed with Git and type
1771
1772 @example
1773 cd [path]/Git
1774 @end example
1775
1776 to position the shell at your new Git repository.
1777
1778 Note: if [path] contains folders with names containing spaces use
1779
1780 @example
1781 cd "[path]/Git"
1782 @end example
1783
1784 Then type
1785
1786 @example
1787 git init
1788 @end example
1789
1790 to initialize your Git repository.
1791
1792 Then type (all on one line; the shell will wrap automatically)
1793
1794 @example
1795 git remote add -ft master origin git://git.sv.gnu.org/lilypond.git
1796 @end example
1797
1798 to download the lilypond master files.
1799
1800 @warning{Be patient!  Even on a broadband connection this can take
1801 10 minutes or more.  Wait for lots of [new tag] messages and the $
1802 prompt.}
1803
1804 We now need to generate a local copy of the downloaded files in a
1805 new local branch.  Your local branch needs to have a name.  It is
1806 usual to call it @q{master} and we shall do that here.
1807
1808 To do this, type
1809
1810 @example
1811 git checkout -b master origin/master
1812 @end example
1813
1814 This creates a second branch called @q{master}.  You will see two
1815 warnings (ignore these), and a message advising you that your
1816 local branch @q{master} has been set up to track the remote
1817 branch.  You now have two branches, a local branch called
1818 @q{master}, and a tracking branch called @q{origin/master}, which
1819 is a shortened form of @q{remotes/origin/master}.
1820
1821 Return to Windows Explorer and look in your Git repository.  You
1822 should see lots of folders.  For example, the LilyPond
1823 documentation can be found in [path]/Git/Documentation/.
1824
1825 The Git bash shell is terminated by typing @code{exit} or by
1826 clicking on the usual Windows close-window widget.
1827
1828 @subsection Git GUI
1829
1830 Almost all subsequent work will use the Git Graphical User
1831 Interface, which avoids having to type command line commands.  To
1832 start Git GUI first start the Git bash shell by clicking on the
1833 desktop icon, and type
1834
1835 @example
1836 cd [path]/Git
1837 git gui
1838 @end example
1839
1840 The Git GUI will open in a new window.  It contains four panels
1841 and 7 pull-down menus.  At this stage do not use any of the
1842 commands under Branch, Commit, Merge or Remote.  These will be
1843 explained later.
1844
1845 The top panel on the left contains the names of files which you
1846 are in the process of editing (Unstaged Changes), and the lower
1847 panel on the left contains the names of files you have finished
1848 editing and have staged ready for committing (Staged Changes).  At
1849 present, these panels will be empty as you have not yet made any
1850 changes to any file.  After a file has been edited and saved the
1851 top panel on the right will display the differences between the
1852 edited file selected in one of the panels on the left and the last
1853 version committed on the current branch.
1854
1855 The panel at bottom right is used to enter a descriptive message
1856 about the change before committing it.
1857
1858 The Git GUI is terminated by entering CNTL-Q while it is the
1859 active window or by clicking on the usual Windows close-window
1860 widget.
1861
1862 @subsection Personalising your local git repository
1863
1864 Open the Git GUI, click on
1865
1866 @example
1867 Edit -> Options
1868 @end example
1869
1870 and enter your name and email address in the left-hand (Git
1871 Repository) panel.  Leave everything else unchanged and save it.
1872
1873 Note that Windows users must leave the default setting for line
1874 endings unchanged.  All files in a git repository must have lines
1875 terminated by just a LF, as this is required for Merge to work,
1876 but Windows files are terminated by CRLF by default.  The git
1877 default setting causes the line endings of files in a Windows git
1878 repository to be flipped automatically between LF and CRLF as
1879 required.  This enables files to be edited by any Windows editor
1880 without causing problems in the git repository.
1881
1882 @subsection Checking out a branch
1883
1884 At this stage you have two branches in your local repository,
1885 both identical.  To see them click on
1886
1887 @example
1888 Branch -> Checkout
1889 @end example
1890
1891 You should have one local branch called @q{master} and one
1892 tracking branch called @q{origin/master}.  The latter is your
1893 local copy of the @q{remotes/origin/master} branch in the master
1894 LilyPond repository.  The local @q{master} branch is where you
1895 will make your local changes.
1896
1897 When a particular branch is selected, i.e., checked out, the files
1898 visible in your repository are changed to reflect the state of the
1899 files on that branch.
1900
1901 @subsection Updating files from @q{remote/origin/master}
1902
1903 Before starting the editing of a file, ensure your local
1904 repository contains the latest version of the files in the remote
1905 repository by first clicking
1906
1907 @example
1908 Remote -> Fetch from -> origin
1909 @end example
1910
1911 @noindent
1912 in the Git GUI.
1913
1914 This will place the latest version of every file, including all
1915 the changes made by others, into the @q{origin/master} branch of
1916 the tracking branches in your git repository.  You can see these
1917 files by checking out this branch, but you must @emph{never} edit
1918 any files while this branch is checked out.  Check out your local
1919 @q{master} branch again.
1920
1921 You then need to merge these fetched files into your local
1922 @q{master} branch by clicking on
1923
1924 @example
1925 Merge -> Local Merge
1926 @end example
1927
1928 @noindent
1929 and if necessary select the local @q{master} branch.
1930
1931 Note that a merge cannot be completed if you have made any local
1932 changes which have not yet been committed.
1933
1934 This merge will update all the files in the @q{master} branch to
1935 reflect the current state of the @q{origin/master} branch.  If any
1936 of the changes conflict with changes you have made yourself
1937 recently you will be notified of the conflict (see below).
1938
1939 @subsection Editing files
1940
1941 First ensure your @q{master} branch is checked out, then simply
1942 edit the files in your local Git repository with your favourite
1943 editor and save them back there.  If any file contains non-ASCII
1944 characters ensure you save it in UTF-8 format.  Git will detect
1945 any changes whenever you restart Git GUI and the file names will
1946 then be listed in the Unstaged Changes panel.  Or you can click
1947 the Rescan button to refresh the panel contents at any time.  You
1948 may break off and resume editing any time.
1949
1950 The changes you have made may be displayed in diff form in the top
1951 right-hand panel of Git GUI by clicking on the file name shown in
1952 one of the left panels.
1953
1954 When your editing is complete, move the files from being Unstaged
1955 to Staged by clicking the document symbol to the left of each
1956 name.  If you change your mind it can be moved back by clicking on
1957 the ticked box to the left of the name.
1958
1959 Finally the changes you have made may be committed to your
1960 @q{master} branch by entering a brief message in the Commit
1961 Message box and clicking the Commit button.
1962
1963 If you wish to amend your changes after a commit has been made,
1964 the original version and the changes you made in that commit may
1965 be recovered by selecting
1966
1967 @example
1968 Commit -> Amend Last Commit
1969 @end example
1970
1971 @noindent
1972 or by checking the Amend Last Commit radio button at bottom right.
1973 This will return the changes to the Staged state, so further
1974 editing made be carried out within that commit.  This must only be
1975 done @emph{before} the changes have been Pushed or sent to your
1976 mentor for Pushing - after that it is too late and corrections
1977 have to be made as a separate commit.
1978
1979
1980 @subsection Sending changes to @q{remotes/origin/master}
1981
1982 If you do not have write access to @q{remotes/origin/master} you
1983 will need to send your changes by email to someone who does.
1984
1985 First you need to create a diff or patch file containing your
1986 changes.  To create this, the file must first be committed.  Then
1987 terminate the Git GUI.  In the git bash shell first cd to your Git
1988 repository with
1989
1990 @example
1991 cd [path]/Git
1992 @end example
1993
1994 if necessary, then produce the patch with
1995
1996 @example
1997 git format-patch origin
1998 @end example
1999
2000 This will create a patch file for all the locally committed files
2001 which differ from @q{origin/master}.  The patch file can be found
2002 in [path]/Git and will have a name formed from the commit message.
2003
2004 @subsection Resolving merge conflicts
2005
2006 As soon as you have committed a changed file your local
2007 @code{master} branch has diverged from @code{origin/master}, and
2008 will remain diverged until your changes have been committed in
2009 @code{remotes/origin/master} and Fetched back into your
2010 @code{origin/master} branch.  Similarly, if a new commit has been
2011 made to @code{remotes/origin/master} by someone else and Fetched,
2012 your local @code{master} branch is divergent.  You can detect a
2013 divergent branch by clicking on
2014
2015 @example
2016 Repository -> Visualise all branch history
2017 @end example
2018
2019 This opens up a very useful new window called @q{gitk}.  Use this
2020 to browse all the commits made by yourself and others.
2021
2022 If the diagram at top left of the resulting window does not show
2023 your @code{master} tag on the same node as the
2024 @code{remotes/origin/master} tag your branch has diverged from
2025 @code{origin/master}.  This is quite normal if files you have
2026 modified yourself have not yet been Pushed to
2027 @code{remotes/origin/master} and Fetched, or if files modified and
2028 committed by others have been Fetched since you last Merged
2029 @code{origin/master} into your local @code{master} branch.
2030
2031 If a file being merged from @code{origin/master} differs from one
2032 you have modified in a way that cannot be resolved automatically
2033 by git, Merge will report a Conflict which you must resolve by
2034 editing the file to create the version you wish to keep.
2035
2036 This could happen if the person updating
2037 @code{remotes/origin/master} for you has added some changes of his
2038 own before committing your changes to
2039 @code{remotes/origin/master}, or if someone else has changed the
2040 same file since you last fetched the file from
2041 @code{remotes/origin/master}.
2042
2043 Open the file in your editor and look for sections which are
2044 delimited with ...
2045
2046 [to be completed when I next have a merge conflict to be sure I
2047 give the right instructions  -td]
2048
2049
2050 @subsection Other actions
2051
2052 The instructions above describe the simplest way of using git on
2053 Windows.  Other git facilities which may usefully supplement these
2054 include
2055
2056 @itemize
2057 @item Using multiple local branches (Create, Rename, Delete)
2058 @item Resetting branches
2059 @item Cherry-picking commits
2060 @item Pushing commits to @w{remote/origin/master}
2061 @item Using gitk to review history
2062 @end itemize
2063
2064 Once familiarity with using git on Windows has been gained the
2065 standard git manuals can be used to learn about these.
2066
2067
2068 @node Repository directory structure
2069 @section Repository directory structure
2070
2071
2072 @c TODO: integrate the roadmap better
2073 @verbatiminclude ROADMAP
2074
2075
2076 @node Other Git documentation
2077 @section Other Git documentation
2078
2079 @itemize
2080 @item
2081 Official git man pages:
2082 @uref{http://www.kernel.org/pub/software/scm/git/docs/}
2083
2084 @item
2085 More in-depth tutorials: @uref{http://git-scm.com/documentation}
2086
2087 @item
2088 Book about git: @uref{http://progit.org/,Pro Git}
2089 @end itemize
2090