Skip to content

Commit 2aa4b2f

Browse files
committed
small changes
1 parent eba3784 commit 2aa4b2f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

book/03-git-branching/1-git-branching.asc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ It moved the HEAD pointer back to point to the master branch, and it reverted th
137137
This also means the changes you make from this point forward will diverge from an older version of the project.
138138
It essentially rewinds the work you've done in your testing branch so you can go in a different direction.
139139

140+
[NOTE]
141+
.Switching branches changes files in your working directory
142+
====
143+
It's important to note that when you switch branches in Git, files in your working directory will change. If you switch to an older branch, your working directory will be reverted to look like it did the last time you committed on that branch. If Git cannot do it cleanly, it will not let you switch at all.
144+
====
145+
140146
Let's make a few changes and commit again:
141147

142148
[source,shell]
@@ -158,12 +164,12 @@ You can also see this easily with the `git log` command. If you run `git log --o
158164
[source,shell]
159165
----
160166
$ git log --oneline --decorate --graph --all
161-
* e6a539b (HEAD, master) made other changes
162-
| * a41d33e (testing) made a change
167+
* c2b9e (HEAD, master) made other changes
168+
| * 87ab2 (testing) made a change
163169
|/
164-
* b1d18f0 add feature #32 - ability to add new formats to the central library
165-
* 9eb453a fixed bug #1328 - stack overflow under certain conditions
166-
* b8a510a initial commit of my project
170+
* f30ab add feature #32 - ability to add new formats to the central library
171+
* 34ac2 fixed bug #1328 - stack overflow under certain conditions
172+
* 98ca9 initial commit of my project
167173
----
168174

169175
Because a branch in Git is in actuality a simple file that contains the 40 character SHA-1 checksum of the commit it points to, branches are cheap to create and destroy.
@@ -238,7 +244,7 @@ All you have to do is switch back to your `master` branch.
238244

239245
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.
240246
It's best to have a clean working state when you switch branches.
241-
There are ways to get around this (namely, stashing and commit amending) that we'll cover later.
247+
There are ways to get around this (namely, stashing and commit amending) that we'll cover <<_git_stashing, later>>.
242248
For now, let's assume you've committed all your changes, so you can switch back to your master branch:
243249

244250
[source,shell]
@@ -248,15 +254,15 @@ Switched to branch 'master'
248254
----
249255

250256
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.
251-
This is an important point to remember: Git resets your working directory to look like the snapshot of the commit that the branch your checkout points to.
257+
This is an important point to remember: when you switch branches, Git resets your working directory to look like it did the last time you committed on that branch.
252258
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.
253259

254260
Next, you have a hotfix to make.
255261
Let's create a hotfix branch on which to work until it's completed:
256262

257263
[source,shell]
258264
----
259-
$ git checkout -b 'hotfix'
265+
$ git checkout -b hotfix
260266
Switched to a new branch 'hotfix'
261267
$ vim index.html
262268
$ git commit -a -m 'fixed the broken email address'
@@ -281,7 +287,7 @@ Fast-forward
281287
----
282288

283289
You'll notice the phrase ``fast-forward'' in that merge.
284-
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.
290+
Because the commit pointed to by the branch you merged in was directly upstream of the commit you're on, Git simply moves the pointer forward.
285291
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.''
286292

287293
Your change is now in the snapshot of the commit pointed to by the `master` branch, and you can deploy the fix.

0 commit comments

Comments
 (0)