Git Apprentice Second Edition 2nd Edition Raywenderlich Tutorial Team Download
Git Apprentice Second Edition 2nd Edition Raywenderlich Tutorial Team Download
https://ebookbell.com/product/git-apprentice-second-edition-2nd-
edition-raywenderlich-tutorial-team-54452352
Git Apprentice Getting Started With Git Commands Concepts 1st Edition
Chris Belanger
https://ebookbell.com/product/git-apprentice-getting-started-with-git-
commands-concepts-1st-edition-chris-belanger-34635248
https://ebookbell.com/product/git-apprentice-by-chris-belanger-and-
bhagat-singh-36344032
https://ebookbell.com/product/git-pocket-guide-a-working-
introduction-1st-edition-richard-silverman-49451698
https://ebookbell.com/product/git-version-control-cookbook-leverage-
version-control-to-transform-your-development-workflow-and-boost-
productivity-2nd-edition-kenneth-geisshirt-emanuele-zattin-rasmus-
voss-aske-olsson-49848068
Git Essentials Developers Guide To Git 1st Edition Franois Dupire
https://ebookbell.com/product/git-essentials-developers-guide-to-
git-1st-edition-franois-dupire-50377272
https://ebookbell.com/product/git-repository-management-
in-30-days-1st-edition-sumit-jaiswal-50418178
https://ebookbell.com/product/git-distributed-version-
controlfundamentals-and-workflows-ren-preiel-bjrn-stachmann-51344514
https://ebookbell.com/product/git-for-humans-1st-edition-demaree-
david-55382370
https://ebookbell.com/product/git-version-control-for-everyone-
ravishankar-somasundaram-55382386
Git Apprentice Git Apprentice
Git Apprentice
Chris Belanger & Bhagat Singh
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without
prior written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an
“as is” basis, without warranty of any kind, express of implied, including but not
limited to the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in
the software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.
raywenderlich.com 2
Git Apprentice
raywenderlich.com 3
Git Apprentice
raywenderlich.com 4
Git Apprentice
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Chapter 3: Committing Your Changes . . . . . . . . . . . . . . . . . . . . . . . 42
What is a commit? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Working trees and staging areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Committing your changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Adding directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Looking at git log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Challenge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Chapter 4: The Staging Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Why staging exists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Undoing staged changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Moving files in Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Deleting files in Git. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Challenge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Chapter 5: Ignoring Files in Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Introducing .gitignore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Nesting .gitignore files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Looking at the global .gitignore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Finding sample .gitignore files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Challenge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Key points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Where to go from here?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Chapter 6: Git Log & History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Viewing Git history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
raywenderlich.com 5
Git Apprentice
raywenderlich.com 6
Git Apprentice
raywenderlich.com 7
L Book License
• You are allowed to use and/or modify the source code in Git Apprentice in as many
apps as you want, with no attribution required.
• You are allowed to use and/or modify all art, images and designs that are included
in Git Apprentice in as many apps as you want, but must include this attribution
line somewhere inside your app: “Artwork/images/designs: from Git Apprentice,
available at www.raywenderlich.com”.
• The source code included in Git Apprentice is for your personal use only. You are
NOT allowed to distribute or sell the source code in Git Apprentice without prior
authorization.
• This book is for your personal use only. You are NOT allowed to sell this book
without prior authorization, or distribute it to friends, coworkers or students; they
would need to purchase their own copies.
All materials provided with this book are provided on an “as is” basis, without
warranty of any kind, express or implied, including but not limited to the warranties
of merchantability, fitness for a particular purpose and noninfringement. In no event
shall the authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising from, out of or in
connection with the software or the use or other dealings in the software.
All trademarks and registered trademarks appearing in this guide are the properties
of their respective owners.
raywenderlich.com 8
Before You Begin
This section tells you a few things you need to know before you get started, such as
what you’ll need for hardware and software, where to find the project files for this
book, and more.
raywenderlich.com 9
i What You Need
• Git 2.32 or later. Git is the software package you’ll use for all the work in this
book. There are installers for macOS, Windows and Linux available for free from
the official Git page here: https://git-scm.com/downloads. We’ve tested this book
on Git 2.32.0, but you can follow along with older versions of Git as well.
raywenderlich.com 10
ii Book Source Code &
Forums
• https://github.com/raywenderlich/gita-materials/tree/editions/2.0
You can download the entire set of materials for the book from that page.
Forum
We’ve also set up an official forum for the book at https://
forums.raywenderlich.com/c/books/git-apprentice. This is a great place to ask
questions about the book or to submit any errors you may find.
raywenderlich.com 11
“For Russ and Skip.”
— Chris Belanger
— Bhagat Singh
raywenderlich.com 12
Git Apprentice About the Team
raywenderlich.com 13
v Acknowledgments
Content Development
We would like to thank Chris Belanger for his work on the previous edition of the
book.We also should mention Sam Davies whose evergreen video course is the basis
of this book.
raywenderlich.com 14
vi Introduction
There are usually two reasons a person picks up a book about Git: one, they are
unusually curious about how the software works at a deeper level; or two, they’re
frustrated and need something to solve their problems now.
Whatever situation brought you here, welcome! I’m happy to have you onboard. I
came to write this book for both of the above reasons. I am a tinkerer and hacker by
nature, and I love going deep into the internals of software to see what makes them
tick. But I, like you, found Git at first to be an inscrutable piece of software. My brain,
which had been trained in software development through the late 1990s, found
version control packages like SVN soothing, with their familiar client-server
architecture, Windows shell integration, and rather straightforward, albeit heavy,
processes.
When I came to use Git and GitHub about seven years ago, I found it inscrutable at
best; it seemed no matter which way I turned, Git was telling me I had a merge
conflict, or it was merging changes from the master branch into my current branch,
or quite often complaining about unstaged changes. And why was it called a “pull
request”, when clearly I was trying to push my changes into the master branch?
Little by little, I learned more about how Git worked; how to solve some of the
common issues I encountered, and I eventually got to a point where I felt
comfortable using it on a daily basis.
raywenderlich.com 15
Git Apprentice Introduction
This book gives a little more background on the why: or, in other words, “Why the
%^&$ did you do that to my repository, Git?!” Underneath the hood, you’ll find that
Git has a rather simple and elegant architecture, which is why it scales so well to the
kinds of globally distributed projects that use Git as their version control software,
via GitHub, GitLab, Bitbucket, or other cloud repository management solutions.
And while GUI-based Git frontends like Tower or GitHub Desktop are great at
minimizing effort, they abstract you away from the actual guts of Git. That’s why this
book takes a command-line-first approach, so that you’ll gain a better understanding
of the various actions that Git takes to manage your repositories — and more
importantly, you’ll gain a better understanding of how to fix things when Git does
things that don’t seem to make much sense.
This book works with a small repository that houses a simple ToDo system based on
text files that hold ideas (both good and bad) ideas for content for the website. It’s an
ideal way to learn about Git without getting bogged down in a particular language or
framework.
The next book in our mastering Git series, Advanced Git, which we encourage you to
explore once you’ve completed this book.
raywenderlich.com 16
Random documents with unrelated
content Scribd suggests to you:
give a single note at the end of each verse “to receive the sound.” It
is one of the most ancient of Chinese musical instruments. When an
instrument is composed of a number of these stones it is called Pien-
ch’ing. Usually sixteen of these stones all the same size are placed
upon a frame of fantastic ornamentation, set in two rows; the
difference in pitch is secured a difference in thickness of each:
otherwise all are alike throughout the scale.
The instrument is exclusively used in court and religious ceremonies,
and it is said that beyond those in the Confucian temples and
imperial palaces it is impossible now to find a complete specimen,
though single stones are sometimes met with.
There is a tradition that about two thousand years ago a complete
stone chime was found in a pool, and that this model was followed
by imperial decree. But this, if correct, does not afford any accurate
guidance or tell us what kind of stone chime was extant during the
old Hsia, Shang, or Chou dynasties; for not an instrument or book of
those periods escaped the great destruction ordered by the Emperor
Che Huang-ti; at least, there is no certain evidence against this
belief. So that, for the determination of the actual date of the
introduction of the supposed equal tempered twelve semitone scale,
we remain in the dark, without a clue. Moreover, when the existing
stone chimes—or, rather, the Yün-lo, or gong chimes constructed to
correspond in scale to the stone chimes upon the same twelve lüs
principle—are submitted to examination of the necessary rigid
enquiry by tests, they do not bear out the true semitonal character
that has been asserted. Mr. Ellis tested two specimens in the South
Kensington Museum, but both differed greatly, and he failed to find
anything like the assumed scale; and such scale as he did find he
was unable to give any theory for. Van Aalst says that
Where then shall we find this semitonal scale, this twelve notes
series comprised within the octave?
Considering how very ancient the stone chime is, the question may
well arise how the pitch was derived or ascertained, since in the
material and dimensions no certain reliance could be placed. Both
the stone chime and the Sheng are attributed to an era some five
thousand years ago (about the time of Noah), and then in those
days the Chinese had long been a musical people. It would be but
natural to conclude that the Sheng conforms most to the lüs the
ancient and the original determinant of pitch, and we may be quite
sure that the pitch given by my pipe is the same to-day as in that
remote age. Neither strings nor stones can pretend to the same
absolute fixity.
But now listen. “Music in China,” says Van Aalst, “has been known
since the remotest antiquity. The first invaders of China certainly
brought with them certain notions of music. The aborigines
themselves had also some kind of musical system, which their
conquerors admired and probably mixed with their own. These
invaders were a band of immigrants fighting their way among the
aborigines, and supposed to have come from the south of the
Caspian Sea; remnants of the original Li, the Kuei, and the Feng
tribes are said to be still in existence in south China.” Is there not
here the hint of a curious problem? By what track came the Phœnix
and the Pan’s pipes both to Greece and to China? Dim, through
sequestered years we should wander back, to some immemorial
age, moss grown with primæval traditions, long ere these lands had
their names, and in the deep recesses of forests untrodden by the
foot of man, peradventure we should find that dwelling place of the
great god Pan whence in the earliest of days he came bringing his
river reeds and his wild music with him.
CHAPTER XIV.
“That the Chinese themselves did not learn agriculture in China is beyond a doubt;
the family life of the Chinese does not go back to a time when the black-haired
people were not agricultural.”
again as to Astronomy:—
“The astronomical knowledge of the Chinese was almost certainly derived from
their kinsmen in Mesopotamia.”
The Chinese affirm that the Emperor Hwang Ti, the Yellow Emperor,
invented the scale of twelve semitones, called the twelve lüs, and
according to the record of date this was 4590 years ago. The pitch
of the notes of all ancient systems was described by lineal
measurements; hence every interval accepted was either the excess
or defect resulting from the division of a greater measure, the
octave, or the fourth. In some way or other the derived proportions
have been grateful to human ears, perhaps because they denote
absence of conflict, or presence of symmetry.
The discovery by the Yellow Emperor as narrated reads somewhat
fabulous. It is stated that he sent his minister Ling Lun to the valley
west of the Kuênlun mountains, where bamboos of regular thickness
grow; that Ling Lun cut the piece of bamboo which is between the
knots, and the sound emitted by this tube when blown across he
considered the bass or tonic; that is our way of naming, not his. The
length was equal to one Chinese foot. He then cut a second pipe two
thirds of the length of the first, which gave a sound a fifth higher,
and continued similar relations from pipe to pipe, and so on, he
completed the series of twelve sounds according to the idea of his
master, and for evermore fixed the musical scale handed down from
generation to generation through thousands of years.
I have shown that Amiot misled us in assigning it to the Sheng, and
I expect he has given currency to other errors. What I do note, and
have assigned the cause for in the argument of the previous chapter,
is the peculiar crowding of the scale with intervals less than a
semitone between f and a; and perhaps this crowding has helped
towards inducing the belief, without question, that the semitonal
scale was intended, but that the making of the instrument was not
done with due exactness, or that the instrument was out of order if
it did not bear out the theory of an equal tempered semitonal
succession through an octave. The theoretical existence of such a
scale is not here called in question: my contention is that the ancient
instruments give no confirmation of having been planned in view of
such a principle. Stranger still, the very scheme to which the learned
writers refer as the basis of the principle, and carefully guarded by
them as an authentic ancient treasure, gives a complete denial to
the whole assumption. I take their own statements, the evidence of
their own authorities, and wonder, when I examine the twelve lüs,
why they never examined them, why from curiosity alone they
sought no corroboration of their statements from the lüs themselves.
In Van Aalst’s book the scheme is fully set out in diagram, the twelve
lüs figured, and all the curious details inserted of the moons and the
hours to which each pipe belongs by some mystical relation which
the Chinese mind perceives; the pipes are arranged in the order in
which they bear to the longest one, which is the prime genitor. Also
there is another diagram, elaborately designed to display the
affinities in a circle, having twelve compartments springing from a
common centre; the kung or fundamental sound being placed as the
hub of a wheel with the other sounds rayed round, each sound
being named. The diagram of pipes shows how the lüs generate one
another, whereas the circle or wheel diagram gives the notes as they
follow in a series. I think that I remember seeing these diagrams in
Amiot’s sixth volume. Very likely Van Aalst has taken them from the
same source. Again, he says, “The lüs are a series of bamboo tubes,
the longest of which measures nine inches, and which are supposed
to render the twelve chromatic semitones of the octave.” It appears
to me that the great source of misunderstanding has been in the
European persistence in regarding “the twelve lüs” as meaning
“twelve semitones”: whereas the Chinese name lüs means laws or
principles.
I have examined these pipes by measures and do not find them in
any way corroborating the semitonal relation; and simply taking the
names accorded to the lüs and set forth in these diagrams, if we
arrange the notes in successive order, neither do they bear out the
scale claimed for them. Let us see: this is how they stand. Twelve
semitones forsooth!
♯ ♯ ♯ ♯ ♯
a— d — e — f ‿ g ‿ g ‿ a ‿ a ‿ b — c — d — f
The Sheng was formerly called the “bird’s nest,” and the peculiar
arrangement of its pipes—the longest of which pipes exceed
considerably the real sounding length—is held by the Chinese to
represent the tail of the phœnix as she sits upon her nest; indeed,
unless we accept the symbolism, the method shown in the
construction is unaccountable.
According to the Chinese there are eight sound giving bodies
corresponding to the eight symbols of Fu Hsi, which they believe are
the expression of all the changes and permutations which take place
in the universe. These eight are stone, metal, silk, bamboo, wood,
skin, gourd, clay, with symbolic relations to the eight points of the
compass and the eight seasons of the year. The Sheng is the
representative of the gourd principle. Originally the bowl was formed
of a portion of a gourd or calabash, although in later times made of
wood and lacquered. This gourd is in shape like a teacup, the top of
which is covered by the insertion of a circle of wood, having a series
of holes around the margin, into which the pipes are fixed; then
there is a neck or mouthpiece shielded by an ivory plate, through
which the performer draws the wind. My instrument is an old one,
has been in this country eighty years or more; and as it has been
here photographed to a scale of one fourth, all the proportions are
preserved in the engraving. The instrument is placed to the mouth
with the pipes slanting to the right shoulder, the right hand
forefinger being placed within the opening seen in the circle of
pipes, and the thumb so placed as to be ready to cover the hole
seen on the second pipe, counting to the left from this opening. The
bowl is held in the hollow of the left hand, with the fingers reaching
upwards to the pipes.
A noticeable feature is that it is the left hand that fingers the
instrument, indicating a very early custom, in that respect. The pipe
engraved here is of full size, and shows the little metal free reed
affixed, which also is drawn at the side full size in its frame. The slot
determining the speaking length of the pipe is at the back, and is
here indicated at the proper position by the side diagram, the length
of pipe above the slot having no particular relation except an
average one of about the same length as the bottom portion
reckoned from the lowest end of the cut. The pipes numbers 3 and 4
have their holes at the inside or back of the pipes in a position to be
covered by the forefinger of the right hand.
Diagram of the
Length of Slot at the Back.
Fig. 29.
ebookbell.com