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