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/03-git-branching/chapter3.asc
+19-18Lines changed: 19 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,7 +136,7 @@ First, let’s say you’re working on your project and have a couple of commits
136
136
.A short and simple commit history
137
137
image::images/18333fig0310-tn.png[A short and simple commit history.]
138
138
139
-
You’ve decided that you’re going to work on issue #53 in whatever issue-tracking system your company uses. To be clear, Git isn’t tied into any particular issue-tracking system; but because issue #53 is a focused topic that you want to work on, you’ll create a new branch in which to work. To create a branch and switch to it at the same time, you can run the `git checkout` command with the `-b` switch:
139
+
You’ve decided that you’re going to work on issue #53 in whatever issue-tracking system your company uses. To create a branch and switch to it at the same time, you can run the `git checkout` command with the `-b` switch:
140
140
141
141
[source,shell]
142
142
----
@@ -158,7 +158,7 @@ $ git checkout iss53
158
158
.Creating a new branch pointer
159
159
image::images/18333fig0311-tn.png[Creating a new branch pointer.]
160
160
161
-
You work on your web site and do some commits. Doing so moves the `iss53` branch forward, because you have it checked out (that is, your HEAD is pointing to it; see <<branch_diagram_c>>):
161
+
You work on your web site and do some commits. Doing so moves the `iss53` branch forward, because you have it checked out (that is, your `HEAD` is pointing to it; see <<branch_diagram_c>>):
162
162
163
163
[source,shell]
164
164
----
@@ -172,12 +172,12 @@ image::images/18333fig0312-tn.png[The iss53 branch has moved forward with your w
172
172
173
173
Now you get the call that there is an issue with the web site, and you need to fix it immediately. With Git, you don’t have to deploy your fix along with the `iss53` changes you’ve made, and you don’t have to put a lot of effort into reverting those changes before you can work on applying your fix to what is in production. All you have to do is switch back to your master branch.
174
174
175
-
However, before you do that, note that if your working directory or staging area has uncommitted changes that conflict with the branch you’re checking out, Git won’t let you switch branches. It’s best to have a clean working state when you switch branches. There are ways to get around this (namely, stashing and commit amending) that we’ll cover later. For now, you’ve committed all your changes, so you can switch back to your master branch:
175
+
However, before you do that, note that if your working directory or staging area has uncommitted changes that conflict with the branch you’re checking out, Git won’t let you switch branches. It’s best to have a clean working state when you switch branches. There are ways to get around this (namely, stashing and commit amending) that we’ll cover later. For now, let's assume you’ve committed all your changes, so you can switch back to your master branch:
176
176
177
177
[source,shell]
178
178
----
179
179
$ git checkout master
180
-
Switched to branch "master"
180
+
Switched to branch 'master'
181
181
----
182
182
183
183
At this point, your project working directory is exactly the way it was before you started working on issue #53, and you can concentrate on your hotfix. This is an important point to remember: Git resets your working directory to look like the snapshot of the commit that the branch you check out points to. It adds, removes, and modifies files automatically to make sure your working copy is what the branch looked like on your last commit to it.
@@ -187,11 +187,11 @@ Next, you have a hotfix to make. Let’s create a hotfix branch on which to work
187
187
[source,shell]
188
188
----
189
189
$ git checkout -b 'hotfix'
190
-
Switched to a new branch "hotfix"
190
+
Switched to a new branch 'hotfix'
191
191
$ vim index.html
192
192
$ git commit -a -m 'fixed the broken email address'
193
-
[hotfix]: created 3a0874c: "fixed the broken email address"
194
-
1 files changed, 0 insertions(+), 1 deletions(-)
193
+
[hotfix 1fb7853] fixed the broken email address
194
+
1 file changed, 2 insertions(+)
195
195
----
196
196
197
197
[[branch_diagram_d]]
@@ -205,12 +205,12 @@ You can run your tests, make sure the hotfix is what you want, and merge it back
205
205
$ git checkout master
206
206
$ git merge hotfix
207
207
Updating f42c576..3a0874c
208
-
Fastforward
209
-
README | 1 -
210
-
1 files changed, 0 insertions(+), 1 deletions(-)
208
+
Fast-forward
209
+
index.html | 2 ++
210
+
1 file changed, 2 insertions(+)
211
211
----
212
212
213
-
You’ll notice the phrase ``Fastforward'' in that merge. Because the commit pointed to by the branch you merged in was directly upstream of the commit you’re on, Git moves the pointer forward. To phrase that another way, when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together – this is called a ``fastforward''.
213
+
You’ll notice the phrase ``Fast-forward'' in that merge. Because the commit pointed to by the branch you merged in was directly upstream of the commit you’re on, Git moves the pointer forward. To phrase that another way, when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together – this is called a ``fast-forward''.
214
214
215
215
Your change is now in the snapshot of the commit pointed to by the `master` branch, and you can deploy your change.
216
216
@@ -233,8 +233,8 @@ $ git checkout iss53
233
233
Switched to branch "iss53"
234
234
$ vim index.html
235
235
$ git commit -a -m 'finished the new footer [issue 53]'
236
-
[iss53]: created ad82d7a: "finished the new footer [issue 53]"
237
-
1 files changed, 1 insertions(+), 0 deletions(-)
236
+
[iss53ad82d7a] finished the new footer [issue 53]
237
+
1 file changed, 1 insertion(+)
238
238
----
239
239
240
240
[[branch_diagram_f]]
@@ -250,10 +250,11 @@ Suppose you’ve decided that your issue #53 work is complete and ready to be me
250
250
[source,shell]
251
251
----
252
252
$ git checkout master
253
+
Switched to branch 'master'
253
254
$ git merge iss53
254
-
Merge made by recursive.
255
+
Merge made by the 'recursive' strategy.
255
256
README | 1 +
256
-
1 files changed, 1 insertions(+), 0 deletions(-)
257
+
1 file changed, 1 insertion(+)
257
258
----
258
259
259
260
This looks a bit different than the `hotfix` merge you did earlier. In this case, your development history has diverged from some older point. Because the commit on the branch you’re on isn’t a direct ancestor of the branch you’re merging in, Git has to do some work. In this case, Git does a simple three-way merge, using the two snapshots pointed to by the branch tips and the common ancestor of the two. <<merge_diagram_a>> highlights the three snapshots that Git uses to do its merge in this case.
@@ -262,15 +263,15 @@ This looks a bit different than the `hotfix` merge you did earlier. In this case
262
263
.Git automatically identifies the best common-ancestor merge base for branch merging
263
264
image::images/18333fig0316-tn.png[Git automatically identifies the best common-ancestor merge base for branch merging.]
264
265
265
-
Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it (see <<merge_diagram_b>>). This is referred to as a merge commit and is special in that it has more than one parent.
266
+
Instead of just moving the branch pointer forward, Git creates a new snapshot that results from this three-way merge and automatically creates a new commit that points to it (see <<merge_diagram_b>>). This is referred to as a merge commit, and is special in that it has more than one parent.
266
267
267
-
It’s worth pointing out that Git determines the best common ancestor to use for its merge base; this is different than CVS or Subversion (before version 1.5), where the developer doing the merge has to figure out the best merge base for themselves. This makes merging a heck of a lot easier in Git than in these other systems.
268
+
It’s worth pointing out that Git determines the best common ancestor to use for its merge base; this is different than older tools like CVS or Subversion (before version 1.5), where the developer doing the merge had to figure out the best merge base for themselves. This makes merging a heck of a lot easier in Git than in these other systems.
268
269
269
270
[[merge_diagram_b]]
270
271
.Git automatically creates a new commit object that contains the merged work
271
272
image::images/18333fig0317-tn.png[Git automatically creates a new commit object that contains the merged work.]
272
273
273
-
Now that your work is merged in, you have no further need for the `iss53` branch. You can delete it and then manually close the ticket in your ticket-tracking system:
274
+
Now that your work is merged in, you have no further need for the `iss53` branch. You can delete it and then close the ticket in your ticket-tracking system:
0 commit comments