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/basic.txt
+3-3
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ To save the state again:
23
23
24
24
=== Add, Delete, Rename ===
25
25
26
-
The above will only keep track of the files that were present when you first ran *git add*. If you add new files or subdirectories, you'll have to tell Git:
26
+
The above only keeps track of the files that were present when you first ran *git add*. If you add new files or subdirectories, you'll have to tell Git:
27
27
28
28
$ git add readme.txt Documentation
29
29
@@ -164,7 +164,7 @@ and your users can upgrade their version by changing to the directory containing
164
164
165
165
$ git pull
166
166
167
-
Your users will never end up with a version of your script you don't want them to see. Obviously this trick works for anything, not just scripts.
167
+
Your users will never end up with a version of your script you don't want them to see.
168
168
169
169
=== What Have I Done? ===
170
170
@@ -193,7 +193,7 @@ fire up any web browser.
193
193
194
194
=== Exercise ===
195
195
196
-
Let A, B, C, D be four successive commits where B is the same as A except some files have been removed. We want to add the files back at D and not at B. How can we do this?
196
+
Let A, B, C, D be four successive commits where B is the same as A except some files have been removed. We want to add the files back at D. How can we do this?
197
197
198
198
There are at least three solutions. Assuming we are at D:
Copy file name to clipboardexpand all lines: en/branch.txt
+15-15
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ Then once you've fixed the bug:
82
82
83
83
and resume work on your original task.
84
84
85
-
You can even merge in the bugfix you just made, either by typing:
85
+
You can even 'merge' in the bugfix you just made, either by typing:
86
86
87
87
$ git merge fixes
88
88
@@ -94,38 +94,38 @@ since you have already pushed the bugfix to the main repository.
94
94
95
95
=== Merging ===
96
96
97
-
With many version control systems, creating branches is easy but merging them
97
+
With some version control systems, creating branches is easy but merging them
98
98
back together is tough. With Git, merging is so trivial that you might be
99
99
unaware of it happening.
100
100
101
101
Indeed, though we have just introduced *git merge*, we encountered merging long ago. The *pull* command in fact fetches commits and then merges them into your current branch. If you have no local changes, then the merge is a 'fast forward', a degenerate case akin to fetching the latest version in a centralized version control system. But if you do have local changes, Git will automatically merge, and report any conflicts.
102
102
103
-
Ordinarily, a commit has exactly one parent, namely, the previous commit.
104
-
Merging other branches creates a commit with at least two parents. This begs
105
-
the question: what commit does `HEAD~10` really refer to? A commit could have
106
-
multiple parents, so which one do we follow?
103
+
Ordinarily, a commit has exactly one 'parent commit', namely, the previous
104
+
commit. Merging branches together produces a commit with at least two parents.
105
+
This begs the question: what commit does `HEAD~10` really refer to? A commit
106
+
could have multiple parents, so which one do we follow?
107
107
108
-
It turns out we follow the first parent at every step. This is usually desired,
109
-
because commits in the current branch always become first parents in a *git
110
-
merge*; frequently you're only concerned with the changes you made in the
108
+
It turns out this notation chooses the first parent every time. This is
109
+
desirable because commits in the current branch become the first parents during
110
+
a merge; frequently you're only concerned with the changes you made in the
111
111
current branch, as opposed to changes merged in from other branches.
112
112
113
113
You can refer to a specific parent with a caret. For example, to show
114
114
the logs from the second parent:
115
115
116
116
$ git log HEAD^2
117
117
118
-
If you want the first parent, you can leave out the number. For example, to
119
-
show the differences with the first parent:
118
+
You may omit the number for the first parent. For example, to show the
119
+
differences with the first parent:
120
120
121
121
$ git diff HEAD^
122
122
123
123
You can combine this notation with other types. For example:
124
124
125
-
$ git checkout 1bd6^^2~10 -b ancient
125
+
$ git checkout 1b6d^^2~10 -b ancient
126
126
127
127
starts a new branch ``ancient'' representing the state 10 commits back from the
128
-
second parent of the first parent of the commit starting with 1bd6.
128
+
second parent of the first parent of the commit starting with 1b6d.
129
129
130
130
=== Uninterrupted Workflow ===
131
131
@@ -230,14 +230,14 @@ You can have multiple stashes, and manipulate them in various ways. See
230
230
=== Work How You Want ===
231
231
232
232
You might wonder if branches are worth the bother. After all, clones are almost
233
-
as fast, and you can use *cd* to switch between them, instead of esoteric Git
233
+
as fast, and you can switch between them with *cd* instead of esoteric Git
234
234
commands.
235
235
236
236
Consider web browsers. Why support multiple tabs as well as multiple windows?
237
237
Because allowing both accommodates a wide variety of styles. Some users like to
238
238
keep only one browser window open, and use tabs for multiple webpages. Others
239
239
might insist on the other extreme: multiple windows with no extra tabs anywhere.
240
-
Yet others prefer something in between.
240
+
Others still prefer something in between.
241
241
242
242
Branching is like tabs for your working directory, and cloning is like opening
243
243
a new browser window. These operations are fast and local, so why not
Copy file name to clipboardexpand all lines: en/clone.txt
+38-15
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
3
3
In older version control systems, checkout is the standard operation to get files. You retrieve a bunch of files in the requested saved state.
4
4
5
-
In Git and other distributed version control systems, cloning is the standard operation. To get files you create a clone of the entire repository. In other words, you practically mirror the central server. Anything the main repository can do, you can do.
5
+
In Git and other distributed version control systems, cloning is the standard operation. To get files, you create a 'clone' of the entire repository. In other words, you practically mirror the central server. Anything the main repository can do, you can do.
6
6
7
7
=== Sync Computers ===
8
8
9
-
This is the reason I first used Git. I can tolerate making tarballs or using *rsync* for backups and basic syncing. But sometimes I edit on my laptop, other times on my desktop, and the two may not have talked to each other in between.
9
+
I can tolerate making tarballs or using *rsync* for backups and basic syncing. But sometimes I edit on my laptop, other times on my desktop, and the two may not have talked to each other in between. This situation drove me to learn Git in the first place.
10
10
11
11
Initialize a Git repository and commit your files on one machine. Then on the other:
12
12
@@ -17,7 +17,7 @@ to create a second copy of the files and Git repository. From now on,
17
17
$ git commit -a
18
18
$ git pull other.computer:/path/to/files HEAD
19
19
20
-
will pull in the state of the files on the other computer into the one you're working on. If you've recently made conflicting edits in the same file, Git will let you know and you should commit again after resolving them.
20
+
will 'pull' in the state of the files on the other computer into the one you're working on. If you've recently made conflicting edits in the same file, Git will let you know and you should commit again after resolving them.
21
21
22
22
=== Classic Source Control ===
23
23
@@ -27,38 +27,61 @@ Initialize a Git repository for your files:
27
27
$ git add .
28
28
$ git commit -m "Initial commit"
29
29
30
-
On the central server, initialize an empty Git repository with some name,
31
-
and start the Git daemon if necessary:
30
+
On the central server, initialize a 'bare repository' in some directory:
32
31
33
-
$ GIT_DIR=proj.git git init
34
-
$ git daemon --detach # it might already be running
For Git hosting services, follow the instructions to setup the initially
37
42
empty Git repository. Typically one fills in a form on a webpage.
38
43
39
-
Push your project to the central server with:
44
+
'Push' your project to the central server with:
40
45
41
46
$ git push git://central.server/path/to/proj.git HEAD
42
47
43
-
The central server now holds a 'bare repository': a repository with no working directory. In other words, the central server has the history of your project, but never contains a snapshot of it. To check out the source, a developer types:
48
+
The bare repository is so named because it contains no working directory and exposes files that are hidden away in the `.git` subdirectory of a normal Git repository. In other words, the central server maintains the history of your project, and never carries a snapshot of any given version.
49
+
50
+
To check out the source, a developer types:
44
51
45
52
$ git clone git://central.server/path/to/proj.git
46
53
47
-
After making changes, the code is checked in to the main server by:
54
+
After making changes, the developer saves changes locally:
48
55
49
56
$ git commit -a
50
-
$ git push
51
57
52
-
If the main server has been updated, the latest version needs to be checked out before the push. To sync to the latest version:
58
+
To update to the latest version:
53
59
54
-
$ git commit -a
55
60
$ git pull
56
61
62
+
Any merge conflicts should be resolved then committed:
63
+
64
+
$ git commit -a
65
+
66
+
To check in local changes into the central repository:
67
+
68
+
$ git push
69
+
70
+
If the main server has new changes due to activity by other developers, the
71
+
push fails, and the developer should pull the latest version, resolve any merge
72
+
conflicts, then try again.
73
+
57
74
=== Push versus pull ===
58
75
59
-
A push is more convenient than a pull in the above example. If we pulled from the server, we would have to login to the server first, and give the pull command the network address of the machine we're pulling from. Firewalls may interfere, and we might not even have shell access to the server.
76
+
A push is more convenient than a pull in the above example. Firstly, pull fails
77
+
on bare repositories (you must 'fetch' instead; we discuss this in a later
78
+
chapter). But even if we kept a normal repository on the central server,
79
+
pulling into it is still cumbersome. Each time, we would have to login to the
80
+
server first, and give the pull command the network address of the machine
81
+
we're pulling from. Firewalls may interfere, and we might not even have shell
82
+
access to the server.
60
83
61
-
However, we usually avoid pushing into a repository, because confusion can ensue if the destination has a working directory with changes. But since a bare repository by definition has no working directory, pushing to a bare repository is a straightforward operation.
84
+
However, apart from this case, we discourage pushing into a repository, because confusion can ensue when the destination has a working directory.
62
85
63
86
In short, while learning Git, only push when the target is a bare repository; otherwise pull.
Copy file name to clipboardexpand all lines: en/grandmaster.txt
+10-8
Original file line number
Diff line number
Diff line change
@@ -86,9 +86,9 @@ But how can you go back to the future? The past commits know nothing of the futu
86
86
87
87
If you have the SHA1 of the original HEAD then:
88
88
89
-
$ git reset 1bd6
89
+
$ git reset 1b6d
90
90
91
-
But suppose you never took it down? Don't worry, for commands like these, Git saves the original HEAD as a tag called ORIG_HEAD, and you can return safe and sound with:
91
+
But suppose you never took it down? Don't worry: for commands like these, Git saves the original HEAD as a tag called ORIG_HEAD, and you can return safe and sound with:
92
92
93
93
$ git reset ORIG_HEAD
94
94
@@ -161,7 +161,7 @@ One popular resident is +workdir/git-new-workdir+. Via clever symlinking, this s
161
161
162
162
$ git-new-workdir an/existing/repo new/directory
163
163
164
-
The new directory and files within can be thought of as a clone, except since the history is shared, the two trees automatically stay in sync. There's no need to merge, push or pull.
164
+
The new directory and the files within can be thought of as a clone, except since the history is shared, the two trees automatically stay in sync. There's no need to merge, push or pull.
165
165
166
166
=== Daring Stunts ===
167
167
@@ -177,7 +177,7 @@ On the other hand, if you specify particular paths for checkout, then there are
177
177
178
178
*Reset*: Reset also fails in the presence of uncommitted changes. To force it through, run:
179
179
180
-
$ git reset --hard 1bd6
180
+
$ git reset --hard 1b6d
181
181
182
182
*Branch*: Deleting branches fails if this causes changes to be lost. To force a deletion, type:
183
183
@@ -200,10 +200,10 @@ directories are expendable, then delete them mercilessly with:
200
200
201
201
Next time, that pesky command will work!
202
202
203
-
=== Improve Your Public Image ===
203
+
=== Preventing Bad Commits ===
204
204
205
205
Stupid mistakes abound in the histories of many of my projects. The most
206
-
frightening are missing files due to forgetting to run *git add*. Luckily I
206
+
frightening are missing files due to a forgotten *git add*. Luckily I
207
207
have yet to lose crucial data though accidental omission because I rarely
208
208
delete original working directories. I typically notice the error a few commits
209
209
later, so the only damage is a bit of missing history and a sheepish admission
@@ -238,5 +238,7 @@ Several git operations support hooks; see *git help hooks*. One can write hooks
238
238
to complain about spelling mistakes in commit messages, add new files, indent
239
239
paragraphs, append an entry to a webpage, play a sound, and so on.
240
240
241
-
We encountered the *post-update* hook earlier when discussing Git over
242
-
HTTP. This hook updates a few files Git needs for non-native communication.
241
+
We activated the sample *post-update* hook earlier when discussing Git over
242
+
HTTP; this causes Git to run this script whenever the head has moved. The
243
+
sample post-update script updates a few files Git needs for communication over
0 commit comments