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