You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/book/01-introduction/chapter1.asc
+66-55Lines changed: 66 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,11 +92,11 @@ The mechanism that Git uses for this checksumming is called a SHA-1 hash. This i
92
92
93
93
24b9da6552252987aa493b52f8696cd6d3b00373
94
94
95
-
You will see these hash values all over the place in Git because it uses them so much. In fact, Git stores everything not by file name but in the Git database addressable by the hash value of its contents.
95
+
You will see these hash values all over the place in Git because it uses them so much. In fact, Git stores everything in its database not by file name but by the hash value of its contents.
96
96
97
97
==== Git Generally Only Adds Data
98
98
99
-
When you do actions in Git, nearly all of them only add data to the Git database. It is very difficult 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 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.
99
+
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 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.
100
100
101
101
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>>.
102
102
@@ -113,92 +113,112 @@ The Git directory is where Git stores the metadata and object database for your
113
113
114
114
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.
115
115
116
-
The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.
116
+
The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s also common to refer to it as the staging area.
117
117
118
118
The basic Git workflow goes something like this:
119
119
120
120
1. You modify files in your working directory.
121
121
2. You stage the files, adding snapshots of them to your staging area.
122
122
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.
123
123
124
-
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>>, you’ll learn more about these states and how you can either take advantage of them or skip the staged part entirely.
124
+
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>>, you’ll learn more about these states and how you can either take advantage of them or skip the staged part entirely.
125
125
126
-
=== Installing Git
127
-
128
-
Let’s get into using some Git. First things first—you have to install it. You can get it a number of ways; the two major ones are to install it from source or to install an existing package for your platform.
129
-
130
-
==== Installing from Source
131
-
132
-
If you can, it’s generally useful to install Git from source, because you’ll get the most recent version. Each version of Git tends to include useful UI enhancements, so getting the latest version is often the best route if you feel comfortable compiling software from source. It is also the case that many Linux distributions contain very old packages; so unless you’re on a very up-to-date distro or are using backports, installing from source may be the best bet.
133
-
134
-
To install Git, you need to have the following libraries that Git depends on: curl, zlib, openssl, expat, and libiconv. 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:
There are a lot of different ways to use Git these days. There are the original command line tools and there are many graphical user interfaces as well of varying capabilities. For this book, we will be using Git on the command line. For one, the command line is the only place you can run *all* Git commands - most of the GUIs only implement some subset of Git functionality for simplicity. If you know how to run the command line version, you can probably also figure out how to run the GUI version, while the opposite is not neccesarily true. Finally, while your choice of graphical client is a matter of personal taste, _all_ users will have the command-line tools installed and available.
141
129
142
-
When you have all the necessary dependencies, you can go ahead and grab the latest snapshot from the Git web site:
143
-
144
-
http://git-scm.com/download
145
-
146
-
Then, compile and install:
130
+
So, we will expect you to know how to open Terminal in Mac or Command Prompt or Powershell in Windows. If you don't know what we're talking about here, you may need to stop and research that quickly so that you can follow the rest of the examples and descriptions in this book.
147
131
148
-
$ tar -zxf git-1.7.2.2.tar.gz
149
-
$ cd git-1.7.2.2
150
-
$ make prefix=/usr/local all
151
-
$ sudo make prefix=/usr/local install
152
-
153
-
After this is done, you can also get Git via Git itself for updates:
Let’s get into using some Git. Even if it's already installed, it's probably a good idea to update to the latest version. You can either install it as a package or via another installer, or download the source code and compile it yourself.
156
135
157
136
==== Installing on Linux
158
137
159
138
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 you’re on Fedora, you can use yum:
160
139
161
-
$ yum install git-core
140
+
$ yum install git
162
141
163
142
Or if you’re on a Debian-based distribution like Ubuntu, try apt-get:
164
143
165
-
$ apt-get install git-core
144
+
$ apt-get install git
145
+
146
+
For more options, there are instructions for installing on several different Unix flavors on the Git website:
147
+
148
+
http://git-scm.com/download/linux
166
149
167
150
==== Installing on Mac
168
151
169
-
There are two easy ways to install Git on a Mac. The easiest is to use the graphical Git installer, which you can download from the Google Code page (see <<git_osx_installer>>).
152
+
There are several ways to install Git on a Mac. The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run 'git' from the Terminal the very first time. If you don't have it installed already, it will prompt you to install it.
153
+
154
+
If you want a more up to date version, you can also install it via a binary installer. An OSX Git installer is maintained and available for download here:
image::images/18333fig0107-tn.png[Git OS X installer.]
176
161
177
-
The other major way is to installGit via MacPorts (`http://www.macports.org`). If you have MacPorts installed, install Git via
162
+
You can also install it as part of the GitHub for Mac install. Their GUI Git tool has an option to install command line tools as well. You can download that tool from the GitHub for Mac website.
178
163
179
-
$ sudo port install git-core +svn +doc +bash_completion +gitweb
180
-
181
-
You don’t have to add all the extras, but you’ll probably want to include +svn in case you ever have to use Git with Subversion repositories (see <<_git_and_other_systems>>).
164
+
http://mac.github.com/
182
165
183
166
==== Installing on Windows
184
167
185
-
Installing Git on Windows is very easy. The msysGit project has one of the easier installation procedures. Simply download the installer exe file from the Google Code page, and run it:
168
+
There are also a few ways to install Git on Windows. You can go to the Git website to have it automatically download the current MsysGit installer.
169
+
170
+
http://git-scm.com/download/win
171
+
172
+
If you want more information on the MsysGit project or build, you can also go directly to their homepage.
186
173
187
-
http://code.google.com/p/msysgit
174
+
http://msysgit.github.io
188
175
189
-
After it’s installed, you have both a command-line version (including an SSH client that will come in handy later) and the standard GUI.
176
+
The GitHub for Windows installer will also install a commandline version of Git as well as the GUI, so that is another easy option. It also works well with Powershell and sets up solid credential caching options and sane CRLF settings, so many people find it a simpler installation option. We'll learn more about both of those things a little later.
190
177
191
178
=== First-Time Git Setup
192
179
193
180
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; they’ll stick around between upgrades. You can also change them at any time by running through the commands again.
194
181
195
-
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. These variables can be stored in three different places:
182
+
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. These variables can be stored in three different places:
196
183
197
184
* `/etc/gitconfig` file: Contains values for every user on the system and all their repositories. If you pass the option` --system` to `git config`, it reads and writes from this file specifically.
198
185
* `~/.gitconfig` file: Specific to your user. You can make Git read and write to this file specifically by passing the `--global` option.
199
-
* 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`.
186
+
* `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`.
187
+
188
+
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 it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
189
+
190
+
==== Installing from Source
200
191
201
-
On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Documents and Settings\$USER` for most people). 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.
192
+
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 tends to make a little less of a difference.
193
+
194
+
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 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:
When you have all the necessary dependencies, you can go ahead and grab the latest tagged release tarball from several places. You can get it via the Kernel.org site.
203
+
204
+
https://www.kernel.org/pub/software/scm/git
205
+
206
+
Or the mirror on the GitHub web site.
207
+
208
+
https://github.com/git/git/releases
209
+
210
+
It's generally a little clearer what the latest version is on the GitHub page, but the kernel.org page also has release signatures if you want to verify your download.
211
+
212
+
Then, compile and install:
213
+
214
+
$ tar -zxf git-1.9.1.tar.gz
215
+
$ cd git-1.9.1
216
+
$ make prefix=/usr all doc info
217
+
$ sudo make prefix=/usr install install-doc install-html install-info
218
+
219
+
After this is done, you can also get Git via Git itself for updates:
@@ -209,20 +229,14 @@ The first thing you should do when you install Git is to set your user name and
209
229
210
230
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 you’re in that project.
211
231
232
+
Many of the GUI tools will help you do this when you first run them as well.
233
+
212
234
==== Your Editor
213
235
214
236
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. By default, Git uses your system’s default editor, which is generally Vi or Vim. If you want to use a different text editor, such as Emacs, you can do the following:
215
237
216
238
$ git config --global core.editor emacs
217
239
218
-
==== Your Diff Tool
219
-
220
-
Another useful option you may want to configure is the default diff tool to use to resolve merge conflicts. Say you want to use vimdiff:
221
-
222
-
$ git config --global merge.tool vimdiff
223
-
224
-
Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools. You can also set up a custom tool; see <<_git_tools>> for more information about doing that.
225
-
226
240
==== Checking Your Settings
227
241
228
242
If you want to check your settings, you can use the `git config --list` command to list all the settings Git can find at that point:
@@ -243,9 +257,6 @@ You can also check what Git thinks a specific key’s value is by typing `git co
243
257
$ git config user.name
244
258
Scott Chacon
245
259
246
-
==== Credential Caching
247
-
248
-
249
260
=== Getting Help
250
261
251
262
If you ever need help while using Git, there are three ways to get the manual page (manpage) help for any of the Git commands:
0 commit comments