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
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ If you make some changes and commit again, the next commit stores a pointer to t
32
32
.Git object data for multiple commits
33
33
image::images/18333fig0302-tn.png[Git object data for multiple commits.]
34
34
35
-
A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
35
+
A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is `master`. As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
36
36
37
37
.Branch pointing into the commit data’s history
38
38
image::images/18333fig0303-tn.png[Branch pointing into the commit data’s history.]
@@ -50,7 +50,7 @@ This creates a new pointer at the same commit you’re currently on (see <<histo
50
50
.Multiple branches pointing into the commit’s data history
51
51
image::images/18333fig0304-tn.png[Multiple branches pointing into the commit’s data history.]
52
52
53
-
How does Git know what branch you’re currently on? It keeps a special pointer called HEAD. Note that this is a lot different than the concept of HEAD in other VCSs you may be used to, such as Subversion or CVS. In Git, this is a pointer to the local branch you’re currently on. In this case, you’re still on master. The git branch command only created a new branch – it didn’t switch to that branch (see <<history_diagram_b>>).
53
+
How does Git know what branch you’re currently on? It keeps a special pointer called `HEAD`. Note that this is a lot different than the concept of `HEAD` in other VCSs you may be used to, such as Subversion or CVS. In Git, this is a pointer to the local branch you’re currently on. In this case, you’re still on master. The `git branch` command only _created_ a new branch – it didn’t switch to that branch (see <<history_diagram_b>>).
54
54
55
55
[[history_diagram_b]]
56
56
.HEAD file pointing to the branch you’re on
@@ -63,7 +63,7 @@ To switch to an existing branch, you run the `git checkout` command. Let’s swi
63
63
$ git checkout testing
64
64
----
65
65
66
-
This moves HEAD to point to the testing branch (see <<history_diagram_c>>).
66
+
This moves `HEAD` to point to the `testing` branch (see <<history_diagram_c>>).
67
67
68
68
[[history_diagram_c]]
69
69
.HEAD points to another branch when you switch branches
@@ -96,7 +96,7 @@ $ git checkout master
96
96
.HEAD moves to another branch on a checkout
97
97
image::images/18333fig0308-tn.png[HEAD moves to another branch on a checkout.]
98
98
99
-
That command did two things. It moved the HEAD pointer back to point to the master branch, and it reverted the files in your working directory back to the snapshot that master points to. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
99
+
That command did two things. It moved the HEAD pointer back to point to the master branch, and it reverted the files in your working directory back to the snapshot that master points to. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch so you can go in a different direction.
100
100
101
101
Let’s make a few changes and commit again:
102
102
@@ -106,14 +106,14 @@ $ vim test.rb
106
106
$ git commit -a -m 'made other changes'
107
107
----
108
108
109
-
Now your project history has diverged (see Figure 3-9). You created and switched to a branch, did some work on it, and then switched back to your main branch and did other work. Both of those changes are isolated in separate branches: you can switch back and forth between the branches and merge them together when you’re ready. And you did all that with simple `branch`and `checkout` commands.
109
+
Now your project history has diverged (see Figure 3-9). You created and switched to a branch, did some work on it, and then switched back to your main branch and did other work. Both of those changes are isolated in separate branches: you can switch back and forth between the branches and merge them together when you’re ready. And you did all that with simple `branch`, `checkout`, and `commit` commands.
110
110
111
111
.The branch histories have diverged
112
112
image::images/18333fig0309-tn.png[The branch histories have diverged.]
113
113
114
114
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. Creating a new branch is as quick and simple as writing 41 bytes to a file (40 characters and a newline).
115
115
116
-
This is in sharp contrast to the way most VCS tools branch, which involves copying all of the project’s files into a second directory. This can take several seconds or even minutes, depending on the size of the project, whereas in Git the process is always instantaneous. Also, because we’re recording the parents when we commit, finding a proper merge base for merging is automatically done for us and is generally very easy to do. These features help encourage developers to create and use branches often.
116
+
This is in sharp contrast to the way most older VCS tools branch, which involves copying all of the project’s files into a second directory. This can take several seconds or even minutes, depending on the size of the project, whereas in Git the process is always instantaneous. Also, because we’re recording the parents when we commit, finding a proper merge base for merging is automatically done for us and is generally very easy to do. These features help encourage developers to create and use branches often.
0 commit comments