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: book/01-introduction/sections/what-is-git.asc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Conceptually, most other systems store information as a list of file-based chang
12
12
These other systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they store as a set of files and the changes made to each file over time (this is commonly described as _delta-based_ version control).
13
13
14
14
.Storing data as changes to a base version of each file
15
-
image::images/deltas.png[Storing data as changes to a base version of each file.]
15
+
image::images/deltas.png[Storing data as changes to a base version of each file]
16
16
17
17
Git doesn't think of or store its data this way.
18
18
Instead, Git thinks of its data more like a series of snapshots of a miniature filesystem.
@@ -21,7 +21,7 @@ To be efficient, if files have not changed, Git doesn't store the file again, ju
21
21
Git thinks about its data more like a *stream of snapshots*.
22
22
23
23
.Storing data as snapshots of the project over time
24
-
image::images/snapshots.png[Git stores data as snapshots of the project over time.]
24
+
image::images/snapshots.png[Git stores data as snapshots of the project over time]
25
25
26
26
This is an important distinction between Git and nearly all other VCSs.
27
27
It makes Git reconsider almost every aspect of version control that most other systems copied from the previous generation.
You've decided that you're going to work on issue #53 in whatever issue-tracking system your company uses.
28
28
To create a new branch and switch to it at the same time, you can run the `git checkout` command with the `-b` switch:
@@ -42,7 +42,7 @@ $ git checkout iss53
42
42
----
43
43
44
44
.Creating a new branch pointer
45
-
image::images/basic-branching-2.png[Creating a new branch pointer.]
45
+
image::images/basic-branching-2.png[Creating a new branch pointer]
46
46
47
47
You work on your website and do some commits.
48
48
Doing so moves the `iss53` branch forward, because you have it checked out (that is, your `HEAD` is pointing to it):
@@ -54,7 +54,7 @@ $ git commit -a -m 'Create new footer [issue 53]'
54
54
----
55
55
56
56
.The `iss53` branch has moved forward with your work
57
-
image::images/basic-branching-3.png[The `iss53` branch has moved forward with your work.]
57
+
image::images/basic-branching-3.png[The `iss53` branch has moved forward with your work]
58
58
59
59
Now you get the call that there is an issue with the website, and you need to fix it immediately.
60
60
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.
image::images/basic-branching-4.png[Hotfix branch based on `master`.]
92
+
image::images/basic-branching-4.png[Hotfix branch based on `master`]
93
93
94
94
You can run your tests, make sure the hotfix is what you want, and finally merge the `hotfix` branch back into your `master` branch to deploy to production.
95
95
You do this with the `git merge` command:(((git commands, merge)))
@@ -111,7 +111,7 @@ To phrase that another way, when you try to merge one commit with a commit that
111
111
Your change is now in the snapshot of the commit pointed to by the `master` branch, and you can deploy the fix.
112
112
113
113
.`master` is fast-forwarded to `hotfix`
114
-
image::images/basic-branching-5.png[`master` is fast-forwarded to `hotfix`.]
114
+
image::images/basic-branching-5.png[`master` is fast-forwarded to `hotfix`]
115
115
116
116
After your super-important fix is deployed, you're ready to switch back to the work you were doing before you were interrupted.
117
117
However, first you'll delete the `hotfix` branch, because you no longer need it -- the `master` branch points at the same place.
@@ -136,7 +136,7 @@ $ git commit -a -m 'Finish the new footer [issue 53]'
136
136
----
137
137
138
138
.Work continues on `iss53`
139
-
image::images/basic-branching-6.png[Work continues on `iss53`.]
139
+
image::images/basic-branching-6.png[Work continues on `iss53`]
140
140
141
141
It's worth noting here that the work you did in your `hotfix` branch is not contained in the files in your `iss53` branch.
142
142
If you need to pull it in, you can merge your `master` branch into your `iss53` branch by running `git merge master`, or you can wait to integrate those changes until you decide to pull the `iss53` branch back into `master` later.
@@ -165,13 +165,13 @@ Because the commit on the branch you're on isn't a direct ancestor of the branch
165
165
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.
166
166
167
167
.Three snapshots used in a typical merge
168
-
image::images/basic-merging-1.png[Three snapshots used in a typical merge.]
168
+
image::images/basic-merging-1.png[Three snapshots used in a typical merge]
169
169
170
170
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.
171
171
This is referred to as a merge commit, and is special in that it has more than one parent.
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/nutshell.asc
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,12 @@ Git then creates a commit object that has the metadata and a pointer to the root
23
23
Your Git repository now contains five objects: three _blobs_ (each representing the contents of one of the three files), one _tree_ that lists the contents of the directory and specifies which file names are stored as which blobs, and one _commit_ with the pointer to that root tree and all the commit metadata.
24
24
25
25
.A commit and its tree
26
-
image::images/commit-and-tree.png[A commit and its tree.]
26
+
image::images/commit-and-tree.png[A commit and its tree]
27
27
28
28
If you make some changes and commit again, the next commit stores a pointer to the commit that came immediately before it.
29
29
30
30
.Commits and their parents
31
-
image::images/commits-and-parents.png[Commits and their parents.]
31
+
image::images/commits-and-parents.png[Commits and their parents]
32
32
33
33
A branch in Git is simply a lightweight movable pointer to one of these commits.
34
34
The default branch name in Git is `master`.
@@ -43,7 +43,7 @@ The only reason nearly every repository has one is that the `git init` command c
43
43
====
44
44
45
45
.A branch and its commit history
46
-
image::images/branch-and-history.png[A branch and its commit history.]
46
+
image::images/branch-and-history.png[A branch and its commit history]
47
47
48
48
[[_create_new_branch]]
49
49
==== Creating a New Branch
@@ -62,7 +62,7 @@ $ git branch testing
62
62
This creates a new pointer to the same commit you're currently on.
63
63
64
64
.Two branches pointing into the same series of commits
65
-
image::images/two-branches.png[Two branches pointing into the same series of commits.]
65
+
image::images/two-branches.png[Two branches pointing into the same series of commits]
66
66
67
67
How does Git know what branch you're currently on?
68
68
It keeps a special pointer called `HEAD`.
@@ -72,7 +72,7 @@ In this case, you're still on `master`.
72
72
The `git branch` command only _created_ a new branch -- it didn't switch to that branch.
73
73
74
74
.HEAD pointing to a branch
75
-
image::images/head-to-master.png[HEAD pointing to a branch.]
75
+
image::images/head-to-master.png[HEAD pointing to a branch]
76
76
77
77
You can easily see this by running a simple `git log` command that shows you where the branch pointers are pointing.
78
78
This option is called `--decorate`.
@@ -102,7 +102,7 @@ $ git checkout testing
102
102
This moves `HEAD` to point to the `testing` branch.
103
103
104
104
.HEAD points to the current branch
105
-
image::images/head-to-testing.png[HEAD points to the current branch.]
105
+
image::images/head-to-testing.png[HEAD points to the current branch]
106
106
107
107
What is the significance of that?
108
108
Well, let's do another commit:
@@ -114,7 +114,7 @@ $ git commit -a -m 'made a change'
114
114
----
115
115
116
116
.The HEAD branch moves forward when a commit is made
117
-
image::images/advance-testing.png[The HEAD branch moves forward when a commit is made.]
117
+
image::images/advance-testing.png[The HEAD branch moves forward when a commit is made]
118
118
119
119
This is interesting, because now your `testing` branch has moved forward, but your `master` branch still points to the commit you were on when you ran `git checkout` to switch branches.
120
120
Let's switch back to the `master` branch:
@@ -137,7 +137,7 @@ To show all of the branches, add `--all` to your `git log` command.
137
137
====
138
138
139
139
.HEAD moves when you checkout
140
-
image::images/checkout-master.png[HEAD moves when you checkout.]
140
+
image::images/checkout-master.png[HEAD moves when you checkout]
141
141
142
142
That command did two things.
143
143
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.
@@ -167,7 +167,7 @@ And you did all that with simple `branch`, `checkout`, and `commit` commands.
You can also see this easily with the `git log` command.
173
173
If you run `git log --oneline --decorate --graph --all` it will print out the history of your commits, showing where your branch pointers are and how your history has diverged.
The easiest way to integrate the branches, as we've already covered, is the `merge` command.
16
16
It performs a three-way merge between the two latest branch snapshots (`C3` and `C4`) and the most recent common ancestor of the two (`C2`), creating a new snapshot (and commit).
17
17
18
18
[[rebasing-merging-example]]
19
19
.Merging to integrate diverged work history
20
-
image::images/basic-rebase-2.png[Merging to integrate diverged work history.]
20
+
image::images/basic-rebase-2.png[Merging to integrate diverged work history]
21
21
22
22
However, there is another way: you can take the patch of the change that was introduced in `C4` and reapply it on top of `C3`.
23
23
In Git, this is called _rebasing_.
@@ -36,7 +36,7 @@ Applying: added staged command
36
36
This operation works by going to the common ancestor of the two branches (the one you're on and the one you're rebasing onto), getting the diff introduced by each commit of the branch you're on, saving those diffs to temporary files, resetting the current branch to the same commit as the branch you are rebasing onto, and finally applying each change in turn.
37
37
38
38
.Rebasing the change introduced in `C4` onto `C3`
39
-
image::images/basic-rebase-3.png[Rebasing the change introduced in `C4` onto `C3`.]
39
+
image::images/basic-rebase-3.png[Rebasing the change introduced in `C4` onto `C3`]
40
40
41
41
At this point, you can go back to the `master` branch and do a fast-forward merge.
42
42
@@ -47,7 +47,7 @@ $ git merge experiment
47
47
----
48
48
49
49
.Fast-forwarding the `master` branch
50
-
image::images/basic-rebase-4.png[Fast-forwarding the `master` branch.]
50
+
image::images/basic-rebase-4.png[Fast-forwarding the `master` branch]
51
51
52
52
Now, the snapshot pointed to by `C4'` is exactly the same as the one that was pointed to by `C5` in <<rebasing-merging-example,the merge example>>.
53
53
There is no difference in the end product of the integration, but rebasing makes for a cleaner history.
@@ -70,7 +70,7 @@ Finally, you went back to your server branch and did a few more commits.
70
70
71
71
[[rbdiag_e]]
72
72
.A history with a topic branch off another topic branch
73
-
image::images/interesting-rebase-1.png[A history with a topic branch off another topic branch.]
73
+
image::images/interesting-rebase-1.png[A history with a topic branch off another topic branch]
74
74
75
75
Suppose you decide that you want to merge your client-side changes into your mainline for a release, but you want to hold off on the server-side changes until it's tested further.
76
76
You can take the changes on `client` that aren't on `server` (`C8` and `C9`) and replay them on your `master` branch by using the `--onto` option of `git rebase`:
@@ -84,7 +84,7 @@ This basically says, ``Take the `client` branch, figure out the patches since it
84
84
It's a bit complex, but the result is pretty cool.
85
85
86
86
.Rebasing a topic branch off another topic branch
87
-
image::images/interesting-rebase-2.png[Rebasing a topic branch off another topic branch.]
87
+
image::images/interesting-rebase-2.png[Rebasing a topic branch off another topic branch]
88
88
89
89
Now you can fast-forward your `master` branch (see <<rbdiag_g>>):
90
90
@@ -96,7 +96,7 @@ $ git merge client
96
96
97
97
[[rbdiag_g]]
98
98
.Fast-forwarding your `master` branch to include the client branch changes
99
-
image::images/interesting-rebase-3.png[Fast-forwarding your `master` branch to include the client branch changes.]
99
+
image::images/interesting-rebase-3.png[Fast-forwarding your `master` branch to include the client branch changes]
100
100
101
101
Let's say you decide to pull in your server branch as well.
102
102
You can rebase the `server` branch onto the `master` branch without having to check it out first by running `git rebase <basebranch> <topicbranch>` -- which checks out the topic branch (in this case, `server`) for you and replays it onto the base branch (`master`):
@@ -110,7 +110,7 @@ This replays your `server` work on top of your `master` work, as shown in <<rbdi
110
110
111
111
[[rbdiag_h]]
112
112
.Rebasing your server branch on top of your `master` branch
113
-
image::images/interesting-rebase-4.png[Rebasing your server branch on top of your `master` branch.]
113
+
image::images/interesting-rebase-4.png[Rebasing your server branch on top of your `master` branch]
114
114
115
115
Then, you can fast-forward the base branch (`master`):
@@ -171,7 +171,7 @@ If you do a `git pull`, you'll create a merge commit which includes both lines o
171
171
172
172
[[_merge_rebase_work]]
173
173
.You merge in the same work again into a new merge commit
174
-
image::images/perils-of-rebasing-4.png[You merge in the same work again into a new merge commit.]
174
+
image::images/perils-of-rebasing-4.png[You merge in the same work again into a new merge commit]
175
175
176
176
If you run a `git log` when your history looks like this, you'll see two commits that have the same author, date, and message, which will be confusing.
177
177
Furthermore, if you push this history back up to the server, you'll reintroduce all those rebased commits to the central server, which can further confuse people.
@@ -199,7 +199,7 @@ So instead of the result we see in <<_merge_rebase_work>>, we would end up with
199
199
200
200
[[_rebase_rebase_work]]
201
201
.Rebase on top of force-pushed rebase work
202
-
image::images/perils-of-rebasing-5.png[Rebase on top of force-pushed rebase work.]
202
+
image::images/perils-of-rebasing-5.png[Rebase on top of force-pushed rebase work]
203
203
204
204
This only works if `C4` and `C4'` that your partner made are almost exactly the same patch.
205
205
Otherwise the rebase won't be able to tell that it's a duplicate and will add another C4-like patch (which will probably fail to apply cleanly, since the changes would already be at least somewhat there).
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/remote-branches.asc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,27 +34,27 @@ If you do some work on your local `master` branch, and, in the meantime, someone
34
34
Also, as long as you stay out of contact with your `origin` server, your `origin/master` pointer doesn't move.
35
35
36
36
.Local and remote work can diverge
37
-
image::images/remote-branches-2.png[Local and remote work can diverge.]
37
+
image::images/remote-branches-2.png[Local and remote work can diverge]
38
38
39
39
To synchronize your work with a given remote, you run a `git fetch <remote>` command (in our case, `git fetch origin`).
40
40
This command looks up which server ``origin'' is (in this case, it's `git.ourcompany.com`), fetches any data from it that you don't yet have, and updates your local database, moving your `origin/master` pointer to its new, more up-to-date position.
41
41
42
42
.`git fetch` updates your remote-tracking branches
43
-
image::images/remote-branches-3.png[`git fetch` updates your remote references.]
43
+
image::images/remote-branches-3.png[`git fetch` updates your remote references]
44
44
45
45
To demonstrate having multiple remote servers and what remote branches for those remote projects look like, let's assume you have another internal Git server that is used only for development by one of your sprint teams.
46
46
This server is at `git.team1.ourcompany.com`.
47
47
You can add it as a new remote reference to the project you're currently working on by running the `git remote add` command as we covered in <<ch02-git-basics-chapter#ch02-git-basics-chapter>>.
48
48
Name this remote `teamone`, which will be your shortname for that whole URL.
49
49
50
50
.Adding another server as a remote
51
-
image::images/remote-branches-4.png[Adding another server as a remote.]
51
+
image::images/remote-branches-4.png[Adding another server as a remote]
52
52
53
53
Now, you can run `git fetch teamone` to fetch everything the remote `teamone` server has that you don't have yet.
54
54
Because that server has a subset of the data your `origin` server has right now, Git fetches no data but sets a remote-tracking branch called `teamone/master` to point to the commit that `teamone` has as its `master` branch.
55
55
56
56
.Remote-tracking branch for `teamone/master`
57
-
image::images/remote-branches-5.png[Remote tracking branch for `teamone/master`.]
57
+
image::images/remote-branches-5.png[Remote tracking branch for `teamone/master`]
0 commit comments