]> git.cworth.org Git - hgbook-git/blob - tour.mdwn
7ea810f6a38728584fc77cdda6faaae440bc4858
[hgbook-git] / tour.mdwn
1 ## Chapter 2
2 A tour of git: the basics
3
4 ### 2.0 Copyright
5
6 This document is a modified version of a document originally titled
7 "Distributed revision control with Mercurial" and originally authored
8 by Bryan O’Sullivan. The original document was obtained from
9 <http://hgbook.red-bean.com/>.
10
11 Copyright © 2006, 2007 Bryan O’Sullivan.
12
13 This material may be distributed only subject to the terms and
14 conditions set forth in version 1.0 of the Open Publication
15 License. Please refer to Appendix D for the license text.
16
17 As this is a modified version, the name of Bryan O'Sullivan is used
18 only to properly credit him with the original text. The appearance of
19 his name here explicitly does not assert or imply his endorsement of
20 this modified document.
21
22 Portions Copyright © 2007 Carl Worth.
23
24 Changes made by Carl include the following:
25
26   * 2007-09-27:
27     * Convert from HTML to markdown source syntax
28     * Eliminate all content except Chapter 2 and Appendix D
29     * Eliminate line numbers from examples
30     * Modified to describe git instead of mercurial
31
32 The source of this modified version can be obtained via git:
33
34         git clone git://cworth.org/git/hgbook-git
35
36 or
37
38         git clone http://cworth.org/git/hgbook-git
39
40 and can be [browsed online](http://git.cworth.org/git/hgbook-git)
41
42 ### 2.1 Installing git on your system
43
44 Prebuilt binary packages of git are available for many popular
45 operating systems. These make it easy to start using git on your
46 computer immediately.
47
48 #### 2.1.1 Linux
49
50 Because each Linux distribution has its own packaging tools, policies,
51 and rate of development, it’s difficult to give a comprehensive set of
52 instructions on how to install git binaries. The version of
53 git that you will end up with can vary depending on how active
54 the person is who maintains the package for your distribution.
55
56 To keep things simple, I will focus on installing git from the
57 command line under the most popular Linux distributions. Most of these
58 distributions provide graphical package managers that will let you
59 install git with a single click. The package name to look for is
60 often git, but is sometimes git-core, (due to an unfortunate name
61 with git, meaning GNU Interactive Tools).
62
63   * Debian
64
65         apt-get install git-core
66
67   * Fedora Core
68
69         yum install git
70
71   * Gentoo
72
73         emerge dev-util/git
74
75   * OpenSUSE
76
77         yum install git
78
79   * Ubuntu
80
81         apt-get install git-core
82
83 #### 2.1.2 Mac OS X
84
85 A git-core package is available through
86 [macports](http://macports.org). Once macports is enabled, the command
87 to install git is:
88
89         port install git-core
90
91 #### 2.1.3 Windows
92
93 Git has long been available as part of cygwin, and works reasonably
94 well in that environment. Some people find cygwin a particularly
95 inelegant approach to running git and would prefer a "native"
96 solution. To this end, the [msysgit
97 project](http://code.google.com/p/msysgit/) is rapidly putting
98 together a solution including various packages with full
99 installers. These include GitMe, a package to install the entire
100 development environment necessary to work on improving the msysgit
101 port of git, and WinGit, a package for installing just git itself
102 without the development environment, (still in Alpha as of September
103 2007).
104
105 ### 2.2 Getting started
106
107 To begin, we’ll use the “git version” command to find out whether git
108 is actually installed properly. Versions 1.5 and newer of git are much
109 more friendly to new users than versions 1.4 and older. If you aren't
110 yet running version 1.5 or newer, it's highly recommended that you
111 upgrade.
112
113         $ git version
114         git version 1.5.3.2
115
116 #### 2.2.1 Built-in help
117
118 Git provides a built-in help system. This is invaluable for those
119 times when you find yourself stuck trying to remember how to run a
120 command. If you are completely stuck, simply run “git help”; it will
121 print a brief list of commonly-used commands, along with a description
122 of what each does. If you ask for help on a specific command (such as
123 "git help init"), it prints more detailed information. [XXX: Does `git
124 help <foo>` work universally as a built-in or does it expect man to be
125 present and just call out to `man git-<foo>`?]
126
127         [XXX: The original hgbook includes the complete output of "hg
128         help init" at this point. I'm not including the corresponding
129         "git help init" output as it would be excessively long. The
130         description alone is quite reasonable, (other than a
131         not-too-helpful aside about the obsolete git-init-db command),
132         but it only comes after a full screen's worth of options
133         details. Might it make sense to have a more summarized help
134         output for "git help <foo>" than all of the documentation
135         available for git-<foo>? And perhaps alos provide a "git -v
136         help" similar to "hg -v help" for more?]
137
138 ### 2.3 Working with a repository
139
140 In git, everything happens inside a repository. The repository
141 for a project contains all of the files that “belong to” that project,
142 along with a historical record of the project’s files.
143
144 There’s nothing particularly magical about a repository; it is simply
145 a directory tree in your filesystem that git treats as
146 special. You can rename or delete a repository any time you like,
147 using either the command line or your file browser.
148
149 #### 2.3.1 Creating a copy of a remote repository
150
151 The "git clone" command is used to create a local copy of a remote
152 repository. This is generally the first git operation you will use
153 when beginning to work with an existing project.
154
155 We've assembled a simple repository that will be used in the examples
156 throughout this chapter. Go ahead and clone this repository now so
157 that you will be able to follow along:
158
159         $ git clone git://cworth.org/git/hello
160         Initialized empty Git repository in /tmp/hello/.git/
161         remote: Generating pack...
162         remote: Done counting 15 objects.
163         remote: Deltifying 15 objects...
164         remote:  100% (15/15) done
165         remote: Total 15 (delta 2), reused 15 (delta remote: 2)
166         Indexing 15 objects...
167          100% (15/15) done
168         Resolving 2 deltas...
169          100% (2/2) done
170
171 If for some reason you are prevented from talking on the git: port,
172 then there is also the capability to clone a repository (less
173 efficiently) over http:
174
175         $ git clone http://cworth.org/git/hello
176         Initialized empty Git repository in /tmp/hello/.git/
177         Getting alternates list for http://cworth.org/git/hello
178         Getting pack list for http://cworth.org/git/hello
179         Getting index for pack 04ecb061314ecbd60fa0610ecf55a1cbf85ea294
180         Getting pack 04ecb061314ecbd60fa0610ecf55a1cbf85ea294
181          which contains a1a0e8b392b17caf50325498df54802fe3c03710
182         walk a1a0e8b392b17caf50325498df54802fe3c03710
183         walk 72d4f10e4a27dbb09ace1503c20dbac1912ee451
184         walk 13ed136b983a9c439eddeea8a1c2076cffbb685f
185         walk 0a633bf58b45fcf1a8299d3c82cd1fd26d3f48f2
186         walk db7117a9dd9a6e57e8632ea5848e1101eee0fbde
187
188 If our clone succeeded, we should now have a local directory called
189 hello. This directory will contain some files.
190
191         $ ls -l
192         total 4
193         drwxr-xr-x 3 cworth cworth 4096 2007-09-27 16:40 hello
194         $ ls hello
195         hello.c  Makefile
196
197 These files have the same contents and history in our repository as
198 they do in the repository we cloned.
199
200 Every git repository is complete, self-contained, and
201 independent. It contains its own private copy of a project’s files and
202 history. A cloned repository remembers the location of the repository
203 it was cloned from, but it does not communicate with that repository,
204 or any other, unless you tell it to.
205
206 What this means for now is that we’re free to experiment with our
207 repository, safe in the knowledge that it’s a private “sandbox” that
208 won’t affect anyone else.
209
210 #### 2.3.2 Creating copy of a local repository
211
212 As mentioned above, a repository can be copied through normal
213 file-copying commands. But it's useful to use "git clone" even when
214 just making a local copy of a repository. Using "git clone" will be
215 much faster and will use much less space than a normal copy. In fact,
216 local clones are impressively fast. Go ahead and make a local clone
217 now as follows:
218
219         $ git clone hello hello-clone
220         Initialized empty Git repository in /tmp/hello-clone/.git/
221         0 blocks
222
223         [XXX Git says "empty" here, (presumably from the git-init
224         part), but shouldn't the command also report the succesful
225         clone which makes it non-empty? And what the heck does "0
226         blocks" mean? This is not friendly output.]
227
228 In fact, let's make a couple more clones at the same time. This isn't
229 just to drive home the speed and storage benefits of local clones, but
230 we'll use each of these cloned repositories in Section 2.8 when
231 discussing how to move commits between repositories:
232
233            $ git clone hello hello-pull
234            $ git clone hello hello-fetch
235            $ git clone hello hello-remote
236
237 #### 2.3.2 What’s in a repository?
238
239 When we take a more detailed look inside a repository, we can see that
240 it contains a directory named .git. This is where git keeps all
241 of its metadata for the repository.
242
243         $ cd hello
244         $ ls -a
245         .  ..  .git  hello.c  Makefile
246
247 The contents of the .git directory and its subdirectories are private
248 to git. Every other file and directory in the repository is
249 yours to do with as you please.
250
251 To introduce a little terminology, the .git directory is the “real”
252 repository, and all of the files and directories that coexist with it
253 are said to live in the working directory. An easy way to remember the
254 distinction is that the repository contains the history of your
255 project, while the working directory contains a snapshot of your
256 project at a particular point in history.
257
258 ### 2.4 A tour through history
259
260 One of the first things we might want to do with a new, unfamiliar
261 repository is understand its history. The “git log” command gives us a
262 view of history.
263
264         $ git log
265         commit a1a0e8b392b17caf50325498df54802fe3c03710
266         Author: Bryan O'Sullivan <bos@serpentine.com>
267         Date:   Tue Sep 6 15:43:07 2005 -0700
268
269             Trim comments.
270
271         commit 72d4f10e4a27dbb09ace1503c20dbac1912ee451
272         Author: Bryan O'Sullivan <bos@serpentine.com>
273         Date:   Tue Sep 6 13:15:58 2005 -0700
274
275             Get make to generate the final binary from a .o file.
276
277         commit 13ed136b983a9c439eddeea8a1c2076cffbb685f
278         Author: Bryan O'Sullivan <bos@serpentine.com>
279         Date:   Tue Sep 6 13:15:43 2005 -0700
280
281             Introduce a typo into hello.c.
282
283         commit 0a633bf58b45fcf1a8299d3c82cd1fd26d3f48f2
284         Author: Bryan O'Sullivan <mpm@selenic.com>
285         Date:   Fri Aug 26 01:21:28 2005 -0700
286
287             Create a makefile
288
289         commit db7117a9dd9a6e57e8632ea5848e1101eee0fbde
290         Author: Bryan O'Sullivan <mpm@selenic.com>
291         Date:   Fri Aug 26 01:20:50 2005 -0700
292
293             Create a standard "hello, world" program
294
295 This command prints a record of output for each change to the project
296 that was recorded. In git terminology, we call each of these recorded
297 events a commit.
298
299 The default fields in a record of output from “git log” are as follows.
300
301   * commit This field consists of a string of 40 hexadecimal characters.
302     This is a unique identifier for referring to particular commits.
303   * Author The identity of the person who authored the commit. This
304     field consist of two sub-fields for the user's name and email
305     address, (or at least an email-like idenitifer). Note that git
306     also stores a separate "Committer" field for the person who
307     commited the change, (since often an author will email a change to
308     a maintainer that commits it). See below for how to instruct "git
309     log" to display it as well.
310   * Date The date and time on which the commit was authored, (again
311     stored separately from the date the change was committed).
312     timezone in which it was created. (The date and time are displayed
313     in the timezone of the person who created the commit.)
314   * commit message The text message that the creator of the commit
315     entered to describe the commit, (generally a one-line summary
316     followed by more supporting text).
317
318 The output of the "git log" command can be made more or less verbose
319 by means of the --pretty option. For example, with "git log
320 --pretty=short" the commit identifier will be omitted and only the
321 first line of each commit message will be shown. And with "git log
322 --pretty=fuller", (the name 'fuller' is in contrast to the default
323 --pretty=full), the committer name and dates will be printed in
324 addition to the author name and dates.
325
326 #### 2.4.1 Commits, revisions, and talking to other people
327
328 As English is a notoriously sloppy language, and computer science has
329 a hallowed history of terminological confusion (why use one term when
330 four will do?), revision control has a variety of words and phrases
331 that mean the same thing. If you are talking about git history
332 with other people, you will find that what we have called a “commit”
333 is often called a "revision". In other systems, a similar notion
334 is referred to as a "changeset". You might even see abbreviations of
335 these terms such as "rev", "change", or even "cset".
336
337 While it may not matter much what word you use to refer to the concept
338 of “a commit”, it's important to know how to name “a specific
339 commit”. We have already seen one means of referring to a particular
340 commit, the 40-character hexadecimal string shown by "git log". These
341 commit identifiers are powerful because they are permanent, unique
342 identifiers that always identify the same commit in any copy of a
343 repository. If two users are examining a working directory associated
344 with the same commit identifier, then those two users have precisely
345 the same contents in all files, and exactly the same history leading
346 to that commit.
347
348 So there are places where it is often important to archive the
349 complete commit identifier, (perhaps in bug-tracking systems to
350 indicate a specific commit that fixes a bug, for example). But often,
351 in more casual settings, it's more convenient to use abbreviated
352 commit identifiers. Git accepts any unique prefix of a commit
353 identifier, (and for reasonably-sized projects the first 8 or 10
354 characters are almost always unique).
355
356 And unlike the permanent commit identifiers, git also provides
357 transient means of identifying commits. In fact, in day-to-day use of
358 git, you will probably use these names more than commit
359 identifiers. One example is branch names, (such as the default
360 "master" branch in any git repository), or any project-specific branch
361 names such as "stable", "experimental", or "crazy-insane-changes". Git
362 also provides a special name "HEAD" which always refers to the current
363 branch.
364
365 #### 2.4.2 Naming related commits
366
367 Git offers simple ways to name revisions that are related to
368 particular revisions in the history. One syntax is the ~ suffix which
369 refers to the parent of a commit, or if followed by a number, to the
370 Nth parent. For example, since "HEAD" refers to the most recent commit
371 in the current branch, "HEAD~", refers to the previous commit, and
372 "HEAD~2" refers to two commits back in the history.
373
374 Another useful syntax is .. which can be used to specify a range of
375 commits. So "origin..master" specifies everything that has been
376 committed to master since it diverged from origin.
377
378 #### 2.4.3 Viewing specific revisions
379
380 You can use "git log" to explore the range syntax just introduced. For
381 example, to see a list of the most recent 3 revisions you can use
382 "HEAD~3..", (the destination of the range is implicitly HEAD in this
383 case):
384
385         $ git log HEAD~3..
386         commit a1a0e8b392b17caf50325498df54802fe3c03710
387         Author: Bryan O'Sullivan <bos@serpentine.com>
388         Date:   Tue Sep 6 15:43:07 2005 -0700
389
390             Trim comments.
391
392         commit 72d4f10e4a27dbb09ace1503c20dbac1912ee451
393         Author: Bryan O'Sullivan <bos@serpentine.com>
394         Date:   Tue Sep 6 13:15:58 2005 -0700
395
396             Get make to generate the final binary from a .o file.
397
398         commit 13ed136b983a9c439eddeea8a1c2076cffbb685f
399         Author: Bryan O'Sullivan <bos@serpentine.com>
400         Date:   Tue Sep 6 13:15:43 2005 -0700
401
402             Introduce a typo into hello.c.
403
404 #### 2.4.4 Other log filters
405
406 Besides filtering by commit identifiers, git allows you to easily
407 filter the log output according to which files (or directories) are
408 modified by listing them after "--" which is necessary to distinguish
409 commit names from file names:
410
411         $ git log -- Makefile
412         commit 72d4f10e4a27dbb09ace1503c20dbac1912ee451
413         Author: Bryan O'Sullivan <bos@serpentine.com>
414         Date:   Tue Sep 6 13:15:58 2005 -0700
415
416             Get make to generate the final binary from a .o file.
417
418         commit 0a633bf58b45fcf1a8299d3c82cd1fd26d3f48f2
419         Author: Bryan O'Sullivan <mpm@selenic.com>
420         Date:   Fri Aug 26 01:21:28 2005 -0700
421
422             Create a makefile
423
424 And "git log" can also filter based on the dates at which commits were
425 created:
426
427         $ git log --since="2 weeks ago" --until="yesterday"
428
429         [XXX: By default, "git log" displays author dates as "Date"
430         but then uses commit dates when given a --since option. That
431         seems like broken defaults to me. Why the inconsistency?]
432
433 Another useful option is -n or --max-count which, unsurprisingly,
434 limits the maximum number of commits to be displayed.
435
436 #### 2.4.5 More detailed information
437
438 While the default information printed by “git log” is useful if you
439 already know what you’re looking for, you may need to see more details
440 of the change, such as the "diffstat" information with --stat:
441
442         $ git log --stat --max-count=3
443         commit a1a0e8b392b17caf50325498df54802fe3c03710
444         Author: Bryan O'Sullivan <bos@serpentine.com>
445         Date:   Tue Sep 6 15:43:07 2005 -0700
446
447             Trim comments.
448
449          hello.c |    8 ++------
450          1 files changed, 2 insertions(+), 6 deletions(-)
451
452         commit 72d4f10e4a27dbb09ace1503c20dbac1912ee451
453         Author: Bryan O'Sullivan <bos@serpentine.com>
454         Date:   Tue Sep 6 13:15:58 2005 -0700
455
456             Get make to generate the final binary from a .o file.
457
458          Makefile |    2 ++
459          1 files changed, 2 insertions(+), 0 deletions(-)
460
461         commit 13ed136b983a9c439eddeea8a1c2076cffbb685f
462         Author: Bryan O'Sullivan <bos@serpentine.com>
463         Date:   Tue Sep 6 13:15:43 2005 -0700
464
465             Introduce a typo into hello.c.
466
467          hello.c |    2 +-
468          1 files changed, 1 insertions(+), 1 deletions(-)
469
470 Or perhaps you'd like to see the actual patch content of each change,
471 which you can get with -p. That commit with the word typo in its name
472 looks suspicious, so let's take a closer look. Remember that we can name
473 it as master~3, HEAD~3, or any prefix of its commit identifier, (such
474 as 13ed136b):
475
476         $ git log -p -n 1 13ed136b
477         commit 13ed136b983a9c439eddeea8a1c2076cffbb685f
478         Author: Bryan O'Sullivan <bos@serpentine.com>
479         Date:   Tue Sep 6 13:15:43 2005 -0700
480
481             Introduce a typo into hello.c.
482
483         diff --git a/hello.c b/hello.c
484         index ed55ec0..80b260c 100644
485         --- a/hello.c
486         +++ b/hello.c
487         @@ -11,6 +11,6 @@
488
489          int main(int argc, char **argv)
490          {
491         -       printf("hello, world!\n");
492         +       printf("hello, world!\");
493                 return 0;
494          }
495
496 Of course, wanting to see all this information for a single commit is
497 such a common operation that it's given its own name in git, "git
498 show". So "git show 13ed136b" is a much easier way to get exactly the
499 same output:
500
501         $ git show 13ed136b
502         commit 13ed136b983a9c439eddeea8a1c2076cffbb685f
503         Author: Bryan O'Sullivan <bos@serpentine.com>
504         Date:   Tue Sep 6 13:15:43 2005 -0700
505
506             Introduce a typo into hello.c.
507
508         diff --git a/hello.c b/hello.c
509         index ed55ec0..80b260c 100644
510         --- a/hello.c
511         +++ b/hello.c
512         @@ -11,6 +11,6 @@
513
514          int main(int argc, char **argv)
515          {
516         -       printf("hello, world!\n");
517         +       printf("hello, world!\");
518                 return 0;
519          }
520
521 ### 2.5 All about command options
522
523 Let’s take a brief break from exploring git commands to discuss
524 a pattern in the way that they work; you may find this useful to keep
525 in mind as we continue our tour.
526
527 Git has a consistent and straightforward approach to dealing
528 with the options that you can pass to commands. It follows the
529 conventions for options that are common to modern Linux and Unix
530 systems.
531
532   * Most options have long names. For example, as we’ve already seen,
533     the “git log" command accepts a `--max-count=<number>` option.
534   * Some options have short, single-character names. Often these are
535     aliases for long commands, (such as `-n <number>` instead of
536     `--max-count=<number>`), but sometimes the option exists in
537     short-form with no long-form equivalent, (such as `-p`). [XXX: It
538     wouldn't hurt to fix this by adding `--patch`, etc. right?]
539   * Long options start with two dashes (e.g. `--max-count`), while short
540     options start with one (e.g. `-n`).
541
542   * Option naming and usage is consistent across commands. For
543     example, every command that lets you specify a commit identifier
544     or range will accept the same expressions, (HEAD~3,
545     origin..master, 72d4f10e, etc), while any command that can be
546     limited by paths will accept the same expressions ("-- doc/
547     some-file.c"), etc.
548
549 Many commands that print output of some kind can be made more quiet by
550 passing the -q or --quiet options.
551
552 ### 2.6 Making and reviewing changes
553
554 Now that we have a grasp of viewing history in git, let’s take a look
555 at making some changes and examining them. You should be working
556 within the "hello" directory that we originally cloned.
557
558 In the repository, we have a file hello.c that contains the classic
559 “hello, world” program. But this program currently has a syntax error
560 and won't compile, (there's a missing 'n' between the '\' and the '"'
561 on the line containing printf). Let's fix that now. You can use a text
562 editor to correct the file, or you can copy-and-paste the sed command
563 below:
564
565         $ sed -i '/printf/s/\\"/\\n"/' hello.c
566
567 After you've made that change, the “git status” command will tell you
568 what git knows about the files in the repository.
569
570         $ ls
571         hello.c  Makefile
572         $ git status
573         # On branch master
574         # Changed but not updated:
575         #   (use "git add <file>..." to update what will be committed)
576         #
577         #       modified:   hello.c
578         #
579         no changes added to commit (use "git add" and/or "git commit -a")
580
581 First "git status" tells us that the current branch is "master". This
582 means that the master branch is what will be updated when we create a
583 new commit.
584
585 Note: In git a branch is a very simple notion---it's simply a name
586 that points to a particular commit, (literally nothing more than a
587 pointer---look at the contents of .git/refs/heads/master if you're
588 curious). The fact that a branch is so light is what makes the
589 creation of new branches an instantaneous operation in git. Together
590 with the ease of merging, git makes branches a joy to work with. But
591 we'll delay talk of branching and merging to a future chapter.
592
593 Next “git status” prints a line with "modified" for each modified
594 file---in this case just hello.c. The “git status” command will not
595 print any output for files that have not been modified.
596
597 Notice that we didn’t need to inform git that we were going to modify
598 the file before we started, or that we had modified the file after we
599 were done; it was able to figure this out itself.
600
601 It’s a little bit helpful to know that we’ve modified hello.c, but we
602 might prefer to know exactly what changes we’ve made to it. To do
603 this, we use the “git diff” command.
604
605         $ git diff
606         diff --git a/hello.c b/hello.c
607         index 9a3ff79..ea364d3 100644
608         --- a/hello.c
609         +++ b/hello.c
610         @@ -7,6 +7,6 @@
611
612          int main(int argc, char **argv)
613          {
614         -       printf("hello, world!\");
615         +       printf("hello, world!\n");
616                 return 0;
617          }
618
619 ### 2.7 Recording changes in a new commit
620
621 We can modify files, build and test our changes, and use “git status”
622 and “git diff” to review our changes, until we’re satisfied with what
623 we’ve done and arrive at a natural stopping point where we want to
624 record our work in a new commit.
625
626 If you'd like, go ahead and build the program now with "make" and run
627 it to ensure it works. Everything should look good so we're just about
628 ready to make a commit. Unsurprisingly, we'll be using "git commit" to
629 do this.
630
631 #### 2.7.1 Introducing yourself to git
632
633 Before you run "git commit" though, you should introduce yourself to
634 git.  Git records your name and email address with each change that
635 you commit, (as both author and committer unless you tell it
636 otherwise), so that you and others will later be able to tell who made
637 each change.
638
639 Git tries to automatically figure out a sensible name and address to
640 attribute to both author and committer if you haven't explicitly told
641 it a name and address. And it tries a lot, (detailed below). If you're
642 not interested in these details, you might want to skip to the next
643 section which explains how to avoid all this guesswork and tell git
644 what your name and email address are.
645
646 Here is a list of all the guessing that git will attempt. It will
647 attempt each of the following methods, in order, (stopping for each of
648 the author and committer name and email as soon as a value is found):
649
650   1. If you specify a --author option to the “git commit” command on
651      the command line, followed by a `"Real Name <email@example.com>"`
652      string, then this name and addresss will be used for the author
653      fields. The committer fields will still be determined as
654      below. This option is very helpful for when applying a commit
655      originally authored by someone other than yourself.
656   2. If any of the `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`,
657      `GIT_COMMITTER`_NAME, or `GIT_COMMITER_EMAIL` environment variables
658      are set, then those values will be used for the corresponding
659      fields.
660   3. If you have a file in your home directory called .gitconfig, with
661      name or email settings in the [user] section, then these values
662      will be used to set any remaining author and committer
663      fields. For more details on the contents of this file, refer to
664      section 2.7.1 below.
665   4. If you have a file in the local repository called .git/config,
666      again with name or email settings in the [user] section, then
667      these values will be used to set any remaining author and
668      committer fields.
669   5. If you have set the `EMAIL` environment variable, this will be used
670      to set author and committer email addresses if still unset.
671   6. git will query your system to find out your real name from
672      available GECOS field and your username, hostname, and domain to
673      construct an email address, (or at least an identifier resembling
674      an email address).
675
676 If all of these mechanisms fail, "git commit" will fail, printing an
677 error message instructing you how to use "git config" to tell git your
678 name and email address.
679
680 You should think of the `GIT_AUTHOR`/`COMMITER_NAME`/`EMAIL` environment
681 variables and the --author option to the “git commit” command as ways
682 to override git’s default selection. For normal use, the simplest and
683 most robust way to set your information is by creating a .gitconfig
684 file, (either manually or with the "git config" command); see below
685 for details.
686
687 ##### Creating a git configuration file
688
689 To set your name and email address, just use the following commands:
690
691         git config --global user.name "Your Name"
692         git config --global user.email "you@example.com"
693
694 The --global option means that this command will set global
695 information, (affecting all repositories on this machine), in the
696 .gitconfig file in your home directory. Alternately, you could omit
697 the --global which would make the change take effect only in the local
698 repository. This is convenient if you want to have different email
699 addresses associated with different projects, for example.
700
701 Of course, git's configuration file is a simple-to-edit plain-text
702 file, so instead of using the above commands, you can also just edit
703 the files directly. Use your favorite editor to create a file called
704 .gitconfig in your home directory, (or if you ran the above commands
705 then it will be there already). The initial contents of your
706 .gitconfig should look like this.
707
708         # This is a git configuration file.
709         [user]
710                 name = Your Name
711                 email = you@example.com
712
713 Similarly, you can make a repository-specific configuration by editing
714 .git/config in the local repository. It will already have some
715 sections present, (created by the "git clone"), just add a [user]
716 section as above.
717
718 The “[user]” line begins a section of the config file, so you can read
719 the “name = ...” line as meaning “set the value of the name item in
720 the user section”. This is the same notion expressed with the
721 "user.name" syntax on the git-config command line.  A section
722 continues until a new section begins, or the end of the file. Git
723 ignores empty lines and treats any text from “#” to the end of a line
724 as a comment.
725
726 ##### Choosing your name and email
727
728 You can use any text you like as the value of the name and email
729 configuration items, since this information is for reading by other
730 people, not for interpreting by git. It is conventional to use your
731 actual name as well as a valid email address. But some people, (notably
732 Linus Torvalds, the original author of git), actually like the default
733 username@hostname convention that git falls back on without any
734 additional information about an email address. There's no requirement
735 that the email address actually be valid, and perhaps it's useful to
736 be reminded which machine was used to create particular commits. So
737 choose the name and email you wish, or follow a particular project's
738 conventions.
739
740 #### 2.7.2 Writing a commit message
741
742 When we commit a change, git drops us into a text editor to
743 enter a message that will describe the modifications we’ve made in
744 this commit. This is called the commit message. It will be a record
745 for readers of what we did and why, and it will be printed by “git log”
746 after we’ve finished committing.
747
748         $ git commit -a
749
750 Note: The -a on the command-line instructs git to commit the new
751 content of *all* tracked files that have been modified. This is a
752 convenience over explicitly listing filenames to be committed on the
753 `git commit` command line. It is useful to use `git commit <files>`
754 when there is a need to commit only some subset of the files that have
755 been modified.
756
757 If new files need to be committed for the first time, just use `git
758 add <file>` before `git commit -a`. If a file needs to be removed,
759 just remove it as normal before committing and `git commit -a` will
760 notice that---it does not need to be explicitly told about the
761 removal.
762
763 The editor that the `git commit` command drops us into will contain an
764 empty line, followed by a number of lines starting with “#”. These
765 lines contain the same information as seen in `git status` before:
766
767         empty line
768         # Please enter the commit message for your changes.
769         # (Comment lines starting with '#' will not be included)
770         # On branch master
771         # Changes to be committed:
772         #   (use "git reset HEAD <file>..." to unstage)
773         #
774         #       modified:   hello.c
775         #
776         # Untracked files:
777         #   (use "git add <file>..." to include in what will be committed)
778         #
779         #       hello
780         #       hello.o
781
782 Notice that two untracked files (hello and hello.o) have now appeared
783 from the build process. Git is reminding us of these in case we
784 intended to commit them as well, (in which case we would need to "git
785 add" them). We don't actually want to commit these files so we will
786 ignore them for now, (and we could tell git to ignore them as well by
787 listing them in a .gitignore file).
788
789 Git will ignore all lines in the commit message that start with “#”;
790 it uses them only to give us information on the commit. Modifying or
791 deleting these lines has no effect.
792
793 #### 2.7.3 Writing a good commit message
794
795 A good commit message will generally have a single line that
796 summarizes the commit, a blank line, and then one or more paragraphs
797 with supporting detail. Since many tools only print the first line of
798 a commit message by default, it’s important that the first line stands
799 alone.
800
801 One example of a first-line-only viewer is "git log
802 --pretty=short". Other examples include graphical history viewers such
803 as gitk and gitview, and web-based viewers such as gitweb and cgit.
804
805 Here’s a real example of a commit message that doesn’t follow
806 this guideline, and hence has a summary that is not readable.
807
808         $ git log --pretty=short
809         commit 3ef5535144da88a854f7930503845cd44506c2e2
810         Author: Censored Person <censored.person@example.org>
811
812             include buildmeister/commondefs.   Add an exports and install
813
814 As far as the remainder of the contents of the commit message are
815 concerned, there are no hard-and-fast rules. git itself doesn’t
816 interpret or care about the contents of the commit message, though
817 your project may have policies that dictate a certain kind of
818 formatting.
819
820 My personal preference is for short, but informative, commit messages
821 that tell me something that I can’t figure out with a quick glance at
822 the output of "git log --stat" or “git log -p", (so repeating the list
823 of all modified files is not useful, for example).
824
825 #### 2.7.4 Aborting a commit
826
827 If you decide that you don’t want to commit while in the middle of
828 editing a commit message, simply exit from your editor without saving
829 the file that it’s editing. This will cause nothing to happen to
830 either the repository or the working directory.
831
832 #### 2.7.5 Admiring our new handiwork
833
834 Once we’ve finished the commit, we can use the “git show” command to
835 display the commit we just created. As discussed previously, this
836 command produces output that is identical to “git log -p”, but for
837 only a single revision, (and the most recent revision by default):
838
839         $ git show
840         commit fd21e5d6c5eedee70137229ebf348c25181812ab
841         Author: Carl Worth <cworth@cworth.org>
842         Date:   Fri Sep 28 12:50:16 2007 -0700
843
844             Fixed the typo so the program actuall complies now.
845
846         diff --git a/hello.c b/hello.c
847         index 9a3ff79..ea364d3 100644
848         --- a/hello.c
849         +++ b/hello.c
850         @@ -7,6 +7,6 @@
851
852          int main(int argc, char **argv)
853          {
854         -       printf("hello, world!\");
855         +       printf("hello, world!\n");
856                 return 0;
857          }
858
859 Note that you will not see the same commit identifier for your commit,
860 even if the change you made is identical to mine. The commit
861 identifier incorporates not only the contents of the files, but commit
862 message, the author and committer names and emails, and the author and
863 commit dates. (OK, so now you probably know enough to be able to guess
864 the right command to produce a commit with exactly the commit
865 identifier shown above. Can you do it?)
866
867 #### 2.7.6 Fixing up a broken commit (before anyone else sees it)
868
869 So now that we've cloned a local repository, made a change to the
870 code, setup our name and email address, and made a careful commit,
871 we're just about ready to share our change with the world. But wait,
872 that commit message has some really embarrassing misspellings in
873 it. Wouldn't it be nice to touch those up before I post this commit
874 with a never-to-be-changed again commit identifier?
875
876 This is the exact situation for which "git commit --amend" was
877 invented. So I can just run that now and fix the broken commit
878 message:
879
880         $ git commit --amend
881
882 Here's the final result:
883
884         $ git show
885         commit 3c54ac672ec1130b36837f1b708054a7a1d402de
886         Author: Carl Worth <cworth@cworth.org>
887         Date:   Fri Sep 28 12:50:16 2007 -0700
888
889             Fixed the typo so the program actually compiles now.
890
891         diff --git a/hello.c b/hello.c
892         index 9a3ff79..ea364d3 100644
893         --- a/hello.c
894         +++ b/hello.c
895         @@ -7,6 +7,6 @@
896
897          int main(int argc, char **argv)
898          {
899         -       printf("hello, world!\");
900         +       printf("hello, world!\n");
901                 return 0;
902          }
903
904 Note that we didn't use "commit -a" this time. This means that "git
905 commit --amend" will amend only the commit message and not any of the
906 actual files being tracked, (even if some of them had been modified
907 between the commits).
908
909 It's also possible to use "git commit -a --amend" to similarly fix up
910 mistakes noticed in code. That will replace the most recent commit
911 with a different commit based on any new changes to files.
912
913 I do feel a little hesitant to mention "git commit -a --amend". It's a
914 handy command for fixing up something like a misspelling in a comment
915 in the code. But if there is anything more significant than that, then
916 it would generally be better to create an additional commit rather
917 than amending an existing commit. This is important for several
918 reasons:
919
920   * The amend operation will destroy a state that was previously saved
921     in a commit. If it's just the commit message being changed, then
922     that's no big deal. But if the contents are being amended, then a
923     mistake could eliminate something valuable.
924
925   * All commits should be logically independent and as small as
926     possible. Abusing "git commit -a --amend" can cause a small commit
927     to grow and acquire unrelated changes.
928
929 It's worth emphasizing the value of minimal, independent commits. The
930 smaller the changes are the more useful the history will be when
931 actually using the history, not just viewing it. This is particularly
932 important when doing "git bisect"---that's a powerful tool for
933 isolating a single commit that introduces a bug. And it's much more
934 helpful when the commit it isolates is as small as possible.
935
936 One advantage of using git over some other systems is that the commit
937 speed is blazingly fast. The tool doesn't punish you at all for
938 committing every time your project is in a state worth saving. "Commit
939 early, commit often" is a well-supported mode of operation with git.
940
941 ### 2.8 Sharing changes
942
943 We mentioned earlier that repositories in git are
944 self-contained. This means that the commit we just created exists
945 only in our hello repository. Let’s look at a few ways that we can
946 propagate this change into other repositories.
947
948 #### 2.8.1 Pulling changes from the original repository
949
950 Recall that in Section 2.3.2 we made several local clones of the hello
951 repository before we made any commits. This allows us to simulate what
952 happens when upstream changes have been committed after you originally
953 cloned.
954
955 The simplest, (and quite common), scenario is that you inherently
956 trust any changes in the original repository and you want to pull
957 these directly into your clone. This might be the case if you are
958 using git simply to track the progress of a project without making any
959 changes.
960
961 In this case, the operation is as simple as just calling "git pull":
962
963         $ cd ../hello-pull
964         $ git pull
965         remote: Generating pack...
966         Unpacking 3 objects...
967          100% (3/3) done
968         remote: Done counting 5 objects.
969         Result has 3 objects.
970         Deltifying 3 objects...
971          100% remote: (3/3) done
972         Total 3 (delta 1), reused 0 (delta 0)
973         * refs/remotes/origin/master: fast forward to branch 'master' of /tmp/hello
974           old..new: a1a0e8b..3c54ac6
975         Updating a1a0e8b..3c54ac6
976         Fast forward
977          hello.c |    2 +-
978          1 files changed, 1 insertions(+), 1 deletions(-)
979
980 XXX: Git is fairly noisy here, but a user has little need to care
981 about the several stages of operation involved here. As a tutorial
982 writer I'd like to say "ignore all that progress stuff, and look at
983 where the stat information starts" but it's hard for a new user to
984 even be able to understand that. I think it would be ideal if all of
985 the progress-tracking spew were reduced to a single line. Something
986 like "Computing (100%) Transferring (100%)" or whatever.
987
988 After (lots!) of progress indication, git gives a report of which
989 files were modified, (which is very useful for getting a quick feel
990 for what happened). If you would like more details on what changes
991 came in, git provides a range that is perfect for examining. Let's
992 take a look (again, the commit identifiers will be different for you
993 --- just copy-and-paste the range that git prints):
994
995         $ git log a1a0e8b..3c54ac6
996         commit 3c54ac672ec1130b36837f1b708054a7a1d402de
997         Author: Carl Worth <cworth@cworth.org>
998         Date:   Fri Sep 28 12:50:16 2007 -0700
999
1000             Fixed the typo so the program actually compiles now.
1001
1002 As expected, we received just the one commit.
1003
1004 So that's all that's needed in the common case. Just run "git pull"
1005 everytime you want to pull in new changes that have landed in the
1006 upstream repository.
1007
1008 Note: Mercurial users who are reading this might wonder if there's a
1009 need for the equivalent of "hg update" after doing a "git pull". And
1010 the answer is no. Unlike mercurial, "git pull", (and "git merge") will
1011 automatically update the working-directory files as necessary.
1012
1013 #### 2.8.2 Using fetch and merge separately to pull
1014
1015 Sometimes you may not know if you want to pull in the changes from the
1016 remote repository or not. It's useful to be able to examine them
1017 before accepting them into our branch. The "git pull" command shown in
1018 the previous section is conceptually the combination of two commands,
1019 "git fetch" and "git merge". We can use these commands separately to
1020 examine the change before accepting it.
1021
1022 So let's do that within the hello-fetch clone we made earlier. First
1023 we will do the fetch:
1024
1025         $ cd ../hello-fetch
1026         $ git fetch
1027         remote: Generating pack...
1028         Unpacking 3 objects...
1029         remote: Done counting 5 objects.
1030         Result has 3 objects.
1031         Deltifying 3 objects...
1032          100% remote: (3/3) done
1033         Total 3 (delta 1), reused 0 (delta 0)
1034          100% (3/3) done
1035         * refs/remotes/origin/master: fast forward to branch 'master' of /tmp/hello/
1036           old..new: a1a0e8b..3c54ac6
1037
1038 You may notice that the output here looks very much like the first
1039 portion of the output from "git pull". This is no coincidence.  The
1040 new changes have been "fetched" into the current repository and are
1041 stored into "origin/master" and have not been into the current
1042 "master" branch. Remember that "master" is our current branch. So now,
1043 "origin/master" is the state of the master branch that exists in the
1044 "origin" repository, (the one we cloned from).
1045
1046 The most convenient way to examine the fetched changes is with the
1047 "master..origin" range notation:
1048
1049         $ git log master..origin
1050         commit 3c54ac672ec1130b36837f1b708054a7a1d402de
1051         Author: Carl Worth <cworth@cworth.org>
1052         Date:   Fri Sep 28 12:50:16 2007 -0700
1053
1054             Fixed the typo so the program actually compiles now.
1055
1056 Another helpful way of visualizing what happened with "git fetch" here
1057 is to run "gitk --all", which gives a graphical representation of all
1058 branches. Here is what it would look like:
1059
1060 [[img gitk-fetch.png]]
1061
1062 Notice that origin/master points to a single commit that was committed
1063 on top of the state pointed to by the "master" branch.
1064
1065 Let's assume we are happy with the changes and we want to include them
1066 into our master branch. To do this we simply run "git merge origin":
1067
1068         $ git merge origin
1069         Updating a1a0e8b..3c54ac6
1070         Fast forward
1071          hello.c |    2 +-
1072          1 files changed, 1 insertions(+), 1 deletions(-)
1073
1074 Again, you'll see that this precisely matches the final portion of the
1075 output from "git pull". Using "git fetch" and "git merge" let us
1076 achieve exactly what "git pull" did, but we were able to stop in the
1077 middle to examine the situation, (and we could have decided to reject
1078 the changes and not merge them---leaving our master branch unchanged).
1079
1080 ##### On merges and "fast forward"
1081
1082 You'll notice that we've been seeing the phrase "fast forward" several
1083 times. This is a special-case operation performed by "git merge" where
1084 a branch can be advanced along a linear sequence. This happens
1085 whenever you pull changes that build directly on top of the same
1086 commit you have as your most recent commit. In other words, there was
1087 never any divergence or simultaneous commits created in parallel in
1088 multiple repositories. If there had been parallel commits, then "git
1089 merge" would actually introduce a new merge commit to tie the two
1090 commits together.
1091
1092 When a non-fast-forward merge occurs, there is always the possibility
1093 that a conflict occurs. In this case, "git merge" will leave conflict
1094 markers in the files and instruct you to resolve the conflicts. When
1095 you are finished, you would issue a "git commit -a" to create the
1096 merge commit.
1097
1098 #### 2.8.3 Using "git remote" to pull changes from other repositories
1099
1100 We've already described how "git pull" will pull in changes from the
1101 repository which was the origin of the clone operation. Git also
1102 provides excellent support for pulling changes from any other
1103 repository as well, (distributed, rather than centralized
1104 development).
1105
1106 If you have a situation where you want to pull a single time from some
1107 repository, then you can simply give the path or URL of the repository
1108 on the "git pull" command line. However, it's often the case that if
1109 you want to pull changes from a repository once, you'll want to pull
1110 changes from that same repository again in the future. This is where
1111 the "git remote" notion is extremely useful---it allows you to
1112 associate simple names, (and behaviors), with remote repository URLs
1113
1114 We've already seen one instance of "git remote" which is the creation
1115 of the "origin" remote which happens automatically during "git
1116 clone". Let's now create another. Let's assume you are going to be
1117 working in the hello-remote repository and you'd like to pull changes
1118 from the hello-pull repository, where your friend "fred" has been
1119 making changes. Here's how to setup the new remote:
1120
1121        $ cd ../hello-remote
1122        $ git remote add fred ../hello-pull
1123
1124 So that's a "git remote add" command line followed by an arbitrary
1125 name you'd like for the new remote (fred) and the URL of the remote
1126 (../hello-pull). Obviously, the URL could be a git:// URL or any other
1127 git-supported URL in addition to a local path.
1128
1129 The "git remote" command is really just a helper for adding some
1130 entries to the .git/config file. You might find it more convenient to
1131 edit that file directly once you get comfortable with things.
1132
1133 At this point the name "fred" will work much like the name "origin"
1134 has worked in previous examples. For example, we can fetch the changes
1135 fred has made with "git fetch fred":
1136
1137         $ git fetch fred
1138         remote: Generating pack...
1139         Unpacking 3 objects...
1140         remote: Done counting 5 objects.
1141         Result has 3 objects.
1142         Deltifying 3 objects...
1143          100% remote: (3/3) done
1144         Total 3 (delta 1), reused 0 (delta 0)
1145          100% (3/3) done
1146         * refs/remotes/fred/master: storing branch 'master' of ../hello-pull
1147           commit: 3c54ac6
1148
1149 Notice that this command-line only differs from the "git fetch" we did
1150 previously by explicitly naming which remote should be fetched. We
1151 could have explicitly said "git fetch origin" earlier.
1152
1153 We can also list all known remote-tracking branches with "git branch
1154 -r":
1155
1156         $ git branch -r
1157           fred/master
1158           origin/HEAD
1159           origin/master
1160
1161 These remote-tracking branches make it very easy to collaborate with
1162 people as they are working on experimental features not yet ready for
1163 upstream inclusion. For example, if fred's latest code is still
1164 trashing filesystems then he might not want to push it out to the
1165 project's primary repository. But he may still want my help with
1166 it. So he can push it to a branch in his own repository for which I've
1167 got a remote. Then on my next "git fetch fred" I might notice a new
1168 branch called fred/trashes-filesystems and I can examine his code with
1169 a command such as "git log ..fred/trashed-filesystems".
1170
1171 So lots of side collaboration can go on easily, and people working
1172 only with the primary repository never even have to see this dangerous
1173 code. It's distributed development at its finest.
1174
1175 #### 2.8.4 Checking out previous revisions
1176
1177 It's often useful to examine the working-tree state of some specific
1178 revision other than the tip of some branch. For example, maybe you
1179 would like to build a particular tagged version, or maybe you'd like
1180 to test the behavior of the code before a particular change was
1181 introduced. To do this, use "git checkout" and pass it the name of any
1182 revision, (with a branch name, a tag name, or any other commit
1183 identifier). For example, to examine our project before the original
1184 typo was introduced:
1185
1186         $ git checkout 0a633bf5
1187         Note: moving to "0a633bf5" which isn't a local branch
1188         If you want to create a new branch from this checkout, you may do so
1189         (now or later) by using -b with the checkout command again. Example:
1190           git checkout -b <new_branch_name>
1191         HEAD is now at 0a633bf... Create a makefile
1192
1193 The note that git gives us is to indicate that we are checking out a
1194 non-branch revision. This is perfectly fine if we are just exploring
1195 history, but if we actually wanted to use this revision as the basis
1196 for new commits, we would first have to create a new branch name as it
1197 describes.
1198
1199 If we were to use "git checkout" with a branch name, then that would
1200 change the current branch, (meaning that any new commits would advance
1201 that branch pointer).
1202
1203 For now, let's return back to the tip of the master branch by just
1204 checking it out again:
1205
1206         $ git checkout master
1207         Previous HEAD position was 0a633bf... Create a makefile
1208         Switched to branch "master"
1209
1210 #### 2.8.5 Pushing changes to another repository
1211
1212 As an unsurprising parallel to "git pull", git also provides "git
1213 push" for pushing changes to another repository. Now, generally the
1214 purpose of pushing to a repository is to have some "collaboration
1215 point" where potentially multiple people might be pushing or
1216 pulling. Because there might be multiple people pushing into the
1217 repository at any point, it wouldn't make sense to have a
1218 working-directory associated with this repository.
1219
1220 For this, git has the notion of a "bare" repository, which is simply a
1221 repository with no working directory. Let's create a new bare
1222 repository and push some changes into it:
1223
1224         $ cd ..
1225         $ mkdir hello-bare
1226         $ cd hello-bare
1227         $ git --bare init --shared
1228
1229 The --shared option sets up the necessary group file permissions so
1230 that other users in my group will be able to push into this repository
1231 as well.
1232
1233 Now lets return to our hello repository and push some changes to this
1234 new repository. Since this is our very first push into this repository
1235 we need to tell git which branches to push. The easiest way to do this
1236 is to use --all to indicate all branches:
1237
1238         $ cd ../hello
1239         $ git push ../hello-bare --all
1240         updating 'refs/heads/master'
1241           from 0000000000000000000000000000000000000000
1242           to   3c54ac672ec1130b36837f1b708054a7a1d402de
1243         Generating pack...
1244         Done counting 18 objects.
1245         Deltifying 18 objects...
1246          100% (18/18) done
1247         Writing 18 objects...
1248          100% (18/18) done
1249         Total 18 (delta 3), reused 15 (delta 2)
1250         Unpacking 18 objects...
1251          100% (18/18) done
1252         refs/heads/master: 0000000000000000000000000000000000000000 -> 3c54ac672ec1130b36837f1b708054a7a1d402de
1253
1254 For subsequent pushes we don't need to specify --all as "git push" by
1255 default pushes all branches that exist in both the local and remote
1256 repositories. Also, as with pull, instead of explicitly specifying a
1257 URL, you may also specify a remote to push to. And by default, after
1258 cloning a repository, "git push" with no other arguments will attempt
1259 to push back to the same origin repository. As this is often exactly
1260 what is wanted, you may find that "git push" alone is often exactly
1261 what you need.
1262
1263 What happens if we try to pull or push changes and the receiving
1264 repository already has those changes? Nothing too exciting.
1265
1266         $ git push ../hello-bare
1267         Everything up-to-date
1268
1269 ## Appendix D
1270 Open Publication License
1271
1272 Version 1.0, 8 June 1999
1273
1274 ### D.1 Requirements on both unmodified and modified versions
1275
1276 The Open Publication works may be reproduced and distributed in whole
1277 or in part, in any medium physical or electronic, provided that the
1278 terms of this license are adhered to, and that this license or an
1279 incorporation of it by reference (with any options elected by the
1280 author(s) and/or publisher) is displayed in the reproduction.
1281
1282 Proper form for an incorporation by reference is as follows:
1283
1284 Copyright (c) year by author’s name or designee. This material may be
1285 distributed only subject to the terms and conditions set forth in the
1286 Open Publication License, vx.y or later (the latest version is
1287 presently available at
1288 [http://www.opencontent.org/openpub/][http://www.opencontent.org/openpub/]).
1289
1290 The reference must be immediately followed with any options elected by
1291 the author(s) and/or publisher of the document (see section D.6).
1292
1293 Commercial redistribution of Open Publication-licensed material is
1294 permitted.
1295
1296 Any publication in standard (paper) book form shall require the
1297 citation of the original publisher and author. The publisher and
1298 author’s names shall appear on all outer surfaces of the book. On all
1299 outer surfaces of the book the original publisher’s name shall be as
1300 large as the title of the work and cited as possessive with respect to
1301 the title.
1302
1303 ### D.2 Copyright
1304
1305 The copyright to each Open Publication is owned by its author(s) or
1306 designee.
1307
1308 ### D.3 Scope of license
1309
1310 The following license terms apply to all Open Publication works,
1311 unless otherwise explicitly stated in the document.
1312
1313 Mere aggregation of Open Publication works or a portion of an Open
1314 Publication work with other works or programs on the same media shall
1315 not cause this license to apply to those other works. The aggregate
1316 work shall contain a notice specifying the inclusion of the Open
1317 Publication material and appropriate copyright notice.
1318
1319 Severability. If any part of this license is found to be unenforceable
1320 in any jurisdiction, the remaining portions of the license remain in
1321 force.
1322
1323 No warranty. Open Publication works are licensed and provided “as is”
1324 without warranty of any kind, express or implied, including, but not
1325 limited to, the implied warranties of merchantability and fitness for
1326 a particular purpose or a warranty of non-infringement.
1327
1328 ### D.4 Requirements on modified works
1329
1330 All modified versions of documents covered by this license, including
1331 translations, anthologies, compilations and partial documents, must
1332 meet the following requirements:
1333
1334   1. The modified version must be labeled as such.
1335   2. The person making the modifications must be identified and the
1336      modifications dated.
1337   3. Acknowledgement of the original author and publisher if
1338      applicable must be retained according to normal academic citation
1339      practices.
1340   4. The location of the original unmodified document must be identified.
1341   5. The original author’s (or authors’) name(s) may not be used to
1342      assert or imply endorsement of the resulting document without the
1343      original author’s (or authors’) permission.
1344
1345 ### D.5 Good-practice recommendations
1346
1347 In addition to the requirements of this license, it is requested from
1348 and strongly recommended of redistributors that:
1349
1350   1. If you are distributing Open Publication works on hardcopy or
1351      CD-ROM, you provide email notification to the authors of your
1352      intent to redistribute at least thirty days before your
1353      manuscript or media freeze, to give the authors time to provide
1354      updated documents. This notification should describe
1355      modifications, if any, made to the document.
1356   2. All substantive modifications (including deletions) be either
1357      clearly marked up in the document or else described in an
1358      attachment to the document.
1359   3. Finally, while it is not mandatory under this license, it is
1360      considered good form to offer a free copy of any hardcopy and
1361      CD-ROM expression of an Open Publication-licensed work to its
1362      author(s).
1363
1364 ### D.6 License options
1365
1366 The author(s) and/or publisher of an Open Publication-licensed
1367 document may elect certain options by appending language to the
1368 reference to or copy of the license. These options are considered part
1369 of the license instance and must be included with the license (or its
1370 incorporation by reference) in derived works.
1371
1372   1. To prohibit distribution of substantively modified versions
1373      without the explicit permission of the author(s). “Substantive
1374      modification” is defined as a change to the semantic content of
1375      the document, and excludes mere changes in format or
1376      typographical corrections.
1377
1378      To accomplish this, add the phrase “Distribution of substantively
1379      modified versions of this document is prohibited without the
1380      explicit permission of the copyright holder.” to the license
1381      reference or copy.
1382
1383   2. To prohibit any publication of this work or derivative works in
1384      whole or in part in standard (paper) book form for commercial
1385      purposes is prohibited unless prior permission is obtained from
1386      the copyright holder.
1387
1388      To accomplish this, add the phrase “Distribution of the work or
1389      derivative of the work in any standard (paper) book form is
1390      prohibited unless prior permission is obtained from the copyright
1391      holder.” to the license reference or copy.