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