Skip to content

Chapter 11 #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Oct 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c5107b9
Ch11: First edit for two sections
ben Sep 16, 2014
5561fa7
Fix broken reference
ben Sep 17, 2014
835cde9
Packfiles and refs
ben Sep 17, 2014
d3d877e
Replace single smart-quotes
ben Sep 17, 2014
7c7160a
Refspec
ben Sep 17, 2014
074439f
Maintenance
ben Sep 18, 2014
c24f22d
Partially-written, partially-organized env vars
ben Sep 20, 2014
a18ec02
Categorization, formatting test
ben Sep 22, 2014
e998870
Tracing progress
ben Sep 22, 2014
233e014
Merge branch 'master' into chapter-11
schacon Sep 24, 2014
fcd36ab
Wrap up tracing section
ben Sep 24, 2014
5c9428c
Getting closer
ben Sep 24, 2014
aea93a7
Diffing and merging
ben Sep 25, 2014
13843c6
Misc. env vars
ben Sep 26, 2014
936c9c5
Cleanups and corrections
ben Sep 26, 2014
5c1163a
Index entry for excludes
ben Sep 26, 2014
ebb56f2
HTTPSmart (part I)
ben Oct 1, 2014
629f7ef
HTTPSmartest
ben Oct 3, 2014
1d12836
remove leftover text in ch7 index
schacon Oct 6, 2014
12b64f0
seems like "we'll" is more natural here
schacon Oct 6, 2014
821cd34
these aren't explained elsewhere, I believe they will be confusing
schacon Oct 6, 2014
947146b
not the commit itself, the string
schacon Oct 6, 2014
88f84a4
a few small clarifications to Objects section
schacon Oct 6, 2014
c08581a
we removed this credentials section
schacon Oct 6, 2014
5231e09
i don't think we really worked much with this earlier, if at all
schacon Oct 6, 2014
5da96e2
quote packfile
schacon Oct 6, 2014
28f54c0
there are now nine preceding chapters
schacon Oct 6, 2014
3d1e852
some of them sort of are meant to be used manually
schacon Oct 6, 2014
540c9ba
add reference for references for cross-reference
schacon Oct 6, 2014
527646d
sometimes tags point to other objects
schacon Oct 6, 2014
e33429f
change to HTTP url and fix formatting
schacon Oct 6, 2014
526cf22
standardize on the github string
schacon Oct 6, 2014
fe217d1
hmm, not sure about this note
schacon Oct 6, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions book/01-introduction/1-introduction.asc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ include::sections/help.asc[]

=== Summary

You should have a basic understanding of what Git is and how its different from the centralized version control system you may have previously been using.
You should also now have a working version of Git on your system thats set up with your personal identity.
Its now time to learn some Git basics.
You should have a basic understanding of what Git is and how it's different from the centralized version control system you may have previously been using.
You should also now have a working version of Git on your system that's set up with your personal identity.
It's now time to learn some Git basics.
14 changes: 7 additions & 7 deletions book/01-introduction/sections/about-version-control.asc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ In addition, you get all this for very little overhead.
==== Local Version Control Systems

(((version control,local)))
Many peoples version-control method of choice is to copy files into another directory (perhaps a time-stamped directory, if theyre clever).
Many people's version-control method of choice is to copy files into another directory (perhaps a time-stamped directory, if they're clever).
This approach is very common because it is so simple, but it is also incredibly error prone.
It is easy to forget which directory youre in and accidentally write to the wrong file or copy over files you dont mean to.
It is easy to forget which directory you're in and accidentally write to the wrong file or copy over files you don't mean to.

To deal with this issue, programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control.

Expand All @@ -39,24 +39,24 @@ image::images/centralized.png[Centralized version control diagram]

This setup offers many advantages, especially over local VCSs.
For example, everyone knows to a certain degree what everyone else on the project is doing.
Administrators have fine-grained control over who can do what; and its far easier to administer a CVCS than it is to deal with local databases on every client.
Administrators have fine-grained control over who can do what; and it's far easier to administer a CVCS than it is to deal with local databases on every client.

However, this setup also has some serious downsides.
The most obvious is the single point of failure that the centralized server represents.
If that server goes down for an hour, then during that hour nobody can collaborate at all or save versioned changes to anything theyre working on.
If the hard disk the central database is on becomes corrupted, and proper backups havent been kept, you lose absolutely everything – the entire history of the project except whatever single snapshots people happen to have on their local machines.
If that server goes down for an hour, then during that hour nobody can collaborate at all or save versioned changes to anything they're working on.
If the hard disk the central database is on becomes corrupted, and proper backups haven't been kept, you lose absolutely everything – the entire history of the project except whatever single snapshots people happen to have on their local machines.
Local VCS systems suffer from this same problem – whenever you have the entire history of the project in a single place, you risk losing everything.

==== Distributed Version Control Systems

(((version control,distributed)))
This is where Distributed Version Control Systems (DVCSs) step in.
In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients dont just check out the latest snapshot of the files: they fully mirror the repository.
In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don't just check out the latest snapshot of the files: they fully mirror the repository.
Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it.
Every checkout is really a full backup of all the data.

.Distributed version control.
image::images/distributed.png[Distributed version control diagram]

Furthermore, many of these systems deal pretty well with having several remote repositories they can work with, so you can collaborate with different groups of people in different ways simultaneously within the same project.
This allows you to set up several types of workflows that arent possible in centralized systems, such as hierarchical models.
This allows you to set up several types of workflows that aren't possible in centralized systems, such as hierarchical models.
32 changes: 16 additions & 16 deletions book/01-introduction/sections/basics.asc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the inform
.Storing data as changes to a base version of each file.
image::images/deltas.png[Storing data as changes to a base version of each file.]

Git doesnt think of or store its data this way.
Git doesn't think of or store its data this way.
Instead, Git thinks of its data more like a set of snapshots of a miniature filesystem.
Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
To be efficient, if files have not changed, Git doesnt store the file again, just a link to the previous identical file it has already stored.
To be efficient, if files have not changed, Git doesn't store the file again, just a link to the previous identical file it has already stored.
Git thinks about its data more like a *stream of snapshots*.

.Storing data as snapshots of the project over time.
Expand All @@ -26,31 +26,31 @@ image::images/snapshots.png[Git stores data as snapshots of the project over tim
This is an important distinction between Git and nearly all other VCSs.
It makes Git reconsider almost every aspect of version control that most other systems copied from the previous generation.
This makes Git more like a mini filesystem with some incredibly powerful tools built on top of it, rather than simply a VCS.
Well explore some of the benefits you gain by thinking of your data this way when we cover Git branching in <<_git_branching>>.
We'll explore some of the benefits you gain by thinking of your data this way when we cover Git branching in <<_git_branching>>.

==== Nearly Every Operation Is Local

Most operations in Git only need local files and resources to operate – generally no information is needed from another computer on your network.
If youre used to a CVCS where most operations have that network latency overhead, this aspect of Git will make you think that the gods of speed have blessed Git with unworldly powers.
If you're used to a CVCS where most operations have that network latency overhead, this aspect of Git will make you think that the gods of speed have blessed Git with unworldly powers.
Because you have the entire history of the project right there on your local disk, most operations seem almost instantaneous.

For example, to browse the history of the project, Git doesnt need to go out to the server to get the history and display it for you – it simply reads it directly from your local database.
For example, to browse the history of the project, Git doesn't need to go out to the server to get the history and display it for you – it simply reads it directly from your local database.
This means you see the project history almost instantly.
If you want to see the changes introduced between the current version of a file and the file a month ago, Git can look up the file a month ago and do a local difference calculation, instead of having to either ask a remote server to do it or pull an older version of the file from the remote server to do it locally.

This also means that there is very little you cant do if youre offline or off VPN.
This also means that there is very little you can't do if you're offline or off VPN.
If you get on an airplane or a train and want to do a little work, you can commit happily until you get to a network connection to upload.
If you go home and cant get your VPN client working properly, you can still work.
If you go home and can't get your VPN client working properly, you can still work.
In many other systems, doing so is either impossible or painful.
In Perforce, for example, you cant do much when you arent connected to the server; and in Subversion and CVS, you can edit files, but you cant commit changes to your database (because your database is offline).
In Perforce, for example, you can't do much when you aren't connected to the server; and in Subversion and CVS, you can edit files, but you can't commit changes to your database (because your database is offline).
This may not seem like a huge deal, but you may be surprised what a big difference it can make.

==== Git Has Integrity

Everything in Git is check-summed before it is stored and is then referred to by that checksum.
This means its impossible to change the contents of any file or directory without Git knowing about it.
This means it's impossible to change the contents of any file or directory without Git knowing about it.
This functionality is built into Git at the lowest levels and is integral to its philosophy.
You cant lose information in transit or get file corruption without Git being able to detect it.
You can't lose information in transit or get file corruption without Git being able to detect it.

The mechanism that Git uses for this checksumming is called a SHA-1 hash.(((SHA-1)))
This is a 40-character string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a file or directory structure in Git.
Expand All @@ -65,10 +65,10 @@ In fact, Git stores everything in its database not by file name but by the hash

When you do actions in Git, nearly all of them only add data to the Git database.
It is hard to get the system to do anything that is not undoable or to make it erase data in any way.
As in any VCS, you can lose or mess up changes you havent committed yet; but after you commit a snapshot into Git, it is very difficult to lose, especially if you regularly push your database to another repository.
As in any VCS, you can lose or mess up changes you haven't committed yet; but after you commit a snapshot into Git, it is very difficult to lose, especially if you regularly push your database to another repository.

This makes using Git a joy because we know we can experiment without the danger of severely screwing things up.
For a more in-depth look at how Git stores its data and how you can recover data that seems lost, see <<_git_objects>>.
For a more in-depth look at how Git stores its data and how you can recover data that seems lost, see <<_undoing>>.

==== The Three States

Expand All @@ -91,15 +91,15 @@ The working directory is a single checkout of one version of the project.
These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit.
Its sometimes referred to as the ``index'', but its also common to refer to it as the staging area.
It's sometimes referred to as the ``index'', but it's also common to refer to it as the staging area.

The basic Git workflow goes something like this:

1. You modify files in your working directory.
2. You stage the files, adding snapshots of them to your staging area.
3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

If a particular version of a file is in the Git directory, its considered committed.
If its modified but has been added to the staging area, it is staged.
If a particular version of a file is in the Git directory, it's considered committed.
If it's modified but has been added to the staging area, it is staged.
And if it was changed since it was checked out but has not been staged, it is modified.
In <<_git_basics_chapter>>, youll learn more about these states and how you can either take advantage of them or skip the staged part entirely.
In <<_git_basics_chapter>>, you'll learn more about these states and how you can either take advantage of them or skip the staged part entirely.
16 changes: 8 additions & 8 deletions book/01-introduction/sections/first-time-setup.asc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== First-Time Git Setup

Now that you have Git on your system, youll want to do a few things to customize your Git environment.
You should have to do these things only once on any given computer; theyll stick around between upgrades.
Now that you have Git on your system, you'll want to do a few things to customize your Git environment.
You should have to do these things only once on any given computer; they'll stick around between upgrades.
You can also change them at any time by running through the commands again.

Git comes with a tool called `git config` that lets you get and set configuration variables that control all aspects of how Git looks and operates.(((git commands, config)))
Expand All @@ -11,30 +11,30 @@ These variables can be stored in three different places:
If you pass the option `--system` to `git config`, it reads and writes from this file specifically.
2. `~/.gitconfig` or `~/.config/git/config` file: Specific to your user.
You can make Git read and write to this file specifically by passing the `--global` option.
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository youre currently using: Specific to that single repository.
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository you're currently using: Specific to that single repository.

Each level overrides values in the previous level, so values in `.git/config` trump those in `/etc/gitconfig`.

On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Users\$USER` for most people).
It also still looks for `/etc/gitconfig`, although its relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
It also still looks for `/etc/gitconfig`, although it's relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.

==== Your Identity

The first thing you should do when you install Git is to set your user name and e-mail address.
This is important because every Git commit uses this information, and its immutably baked into the commits you start creating:
This is important because every Git commit uses this information, and it's immutably baked into the commits you start creating:

$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]

Again, you need to do this only once if you pass the `--global` option, because then Git will always use that information for anything you do on that system.
If you want to override this with a different name or e-mail address for specific projects, you can run the command without the `--global` option when youre in that project.
If you want to override this with a different name or e-mail address for specific projects, you can run the command without the `--global` option when you're in that project.

Many of the GUI tools will help you do this when you first run them.

==== Your Editor

Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message.
If not configured, Git uses your systems default editor, which is generally Vim.
If not configured, Git uses your system's default editor, which is generally Vim.
If you want to use a different text editor, such as Emacs, you can do the following:

$ git config --global core.editor emacs
Expand All @@ -60,7 +60,7 @@ If you want to check your settings, you can use the `git config --list` command
You may see keys more than once, because Git reads the same key from different files (`/etc/gitconfig` and `~/.gitconfig`, for example).
In this case, Git uses the last value for each unique key it sees.

You can also check what Git thinks a specific keys value is by typing `git config <key>`:(((git commands, config)))
You can also check what Git thinks a specific key's value is by typing `git config <key>`:(((git commands, config)))

$ git config user.name
John Doe
2 changes: 1 addition & 1 deletion book/01-introduction/sections/help.asc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ For example, you can get the manpage help for the config command by running(((gi
$ git help config

These commands are nice because you can access them anywhere, even offline.
If the manpages and this book arent enough and you need in-person help, you can try the `#git` or `#github` channel on the Freenode IRC server (irc.freenode.net).
If the manpages and this book aren't enough and you need in-person help, you can try the `#git` or `#github` channel on the Freenode IRC server (irc.freenode.net).
These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.(((IRC)))
4 changes: 2 additions & 2 deletions book/01-introduction/sections/history.asc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Linux kernel is an open source software project of fairly large scope.(((Lin
For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files.
In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.(((BitKeeper)))

In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tools free-of-charge status was revoked.
In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool's free-of-charge status was revoked.
This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper.(((Linus Torvalds)))
Some of the goals of the new system were as follows:

Expand All @@ -17,4 +17,4 @@ Some of the goals of the new system were as follows:
* Able to handle large projects like the Linux kernel efficiently (speed and data size)

Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities.
Its incredibly fast, its very efficient with large projects, and it has an incredible branching system for non-linear development (See <<_git_branching>>).
It's incredibly fast, it's very efficient with large projects, and it has an incredible branching system for non-linear development (See <<_git_branching>>).
8 changes: 4 additions & 4 deletions book/01-introduction/sections/installing.asc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ This book was written using Git version *2.0.0*. Though most of the commands we

(((Linux, installing)))
If you want to install Git on Linux via a binary installer, you can generally do so through the basic package-management tool that comes with your distribution.
If youre on Fedora for example, you can use yum:
If you're on Fedora for example, you can use yum:

$ yum install git

If youre on a Debian-based distribution like Ubuntu, try apt-get:
If you're on a Debian-based distribution like Ubuntu, try apt-get:

$ apt-get install git

Expand Down Expand Up @@ -57,11 +57,11 @@ You can download this from the GitHub for Windows website, at http://windows.git

==== Installing from Source

Some people may instead find it useful to install Git from source, because youll get the most recent version.
Some people may instead find it useful to install Git from source, because you'll get the most recent version.
The binary installers tend to be a bit behind, though as Git has matured in recent years, this has made less of a difference.

If you do want to install Git from source, you need to have the following libraries that Git depends on: curl, zlib, openssl, expat, and libiconv.
For example, if youre on a system that has yum (such as Fedora) or apt-get (such as a Debian based system), you can use one of these commands to install all of the dependencies:
For example, if you're on a system that has yum (such as Fedora) or apt-get (such as a Debian based system), you can use one of these commands to install all of the dependencies:

$ yum install curl-devel expat-devel gettext-devel \
openssl-devel zlib-devel
Expand Down
Loading