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