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