Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 933 lines (771 sloc) 45.553 kB
6de91d1 @cbx33 Added chap4 file
authored
1 % chap4.tex - Week 4
2 \cleardoublepage
3 %\phantomsection
5fe5bcb @cbx33 Added Week tags
authored
4 \chapter{Week 4 - Branching and Merging}
06d42f4 @cbx33 Taken extra lines out
authored
5 \section{Day 1 - ``We're getting somewhere''}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
6 \subsection{Planting trees}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
7 Tamagoyaki Inc have now realised that they have to take these things slow and steady if they want to implement a stable and robust system.
8 This week, they are going to start actually using branches and merging in changes, probably one of the largest topics to cover when doing any type of collaborative development.
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
9
ae10c38 @cbx33 Updated TODO.topics
authored
10 \begin{trenches}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
11 ``Dude!'' shouted Eugene from across the office.
12 ``Dude!!'' he repeated.
ae10c38 @cbx33 Updated TODO.topics
authored
13
a77cdf2 Fix speling
Johan Sageryd authored
14 No one looked up and the hum of the computers seemed to drown out the murmurs of voices and clicking of keys.
ae10c38 @cbx33 Updated TODO.topics
authored
15
1ca454d Tidy up dialogue lines
Johan Sageryd authored
16 ``Dud\ldots''
17 He was cut off by another voice.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
18 It was Klaus.
ae10c38 @cbx33 Updated TODO.topics
authored
19
1ca454d Tidy up dialogue lines
Johan Sageryd authored
20 ``Maybe if you gave us some indication of who you were addressing Eugene,'' said Klaus in his usual matter-of-factly tone,
21 ``we may actually be able to help you.''
ae10c38 @cbx33 Updated TODO.topics
authored
22
62c1481 Squash double-space
Johan Sageryd authored
23 ``John!'' Shouted Eugene, as if ignoring Klaus entirely.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
24 The manager hadn't looked up from his monitor as he had advised the tools guy and he now sat there continuing to type with one hand, the other reaching over and yanking out the earbud that was playing a droning beat in John's ear.
ae10c38 @cbx33 Updated TODO.topics
authored
25
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
26 ``Ouch!'' said John, slightly startled.
ae10c38 @cbx33 Updated TODO.topics
authored
27
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
28 ``Dork wants you,'' said Klaus, using his pet name for Eugene.
ae10c38 @cbx33 Updated TODO.topics
authored
29
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
30 John walked over to Eugene.
31 ``Sup?!''
ae10c38 @cbx33 Updated TODO.topics
authored
32
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
33 ``I don't get branches,'' said the developer.
34 ``I mean I don't get what the heck they do, why I would ever want to use them, and how are they even different to tags anyway?''
ae10c38 @cbx33 Updated TODO.topics
authored
35 \end{trenches}
36
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
37 First, we should probably start off by answering that very question and describing what branches are and what they can be used for.
38 In Git, a branch is just a pointer to a commit in the repository.
39 At first glance this might not seem any different to a tag.
40 A tag points to a commit, so does a branch.
62c1481 Squash double-space
Johan Sageryd authored
41 So what distinguishes between the two? Let us start playing with branches a little and the answer will become obvious in a while.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
42 Branches allow you to try things out and even keep a history of the things you try without actually affecting your main branch.
43 In essence you are able to take things in a completely different direction, safe in the knowledge that your core code base will be safe.
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
44
45 This is best illustrated by a little demonstration, so we are going to take our testing repository and branch off to try out new, wonderful and wacky things.
46
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
47 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
48 john@satsuki:~/coderepo$ ls
e4ef43f @cbx33 Added new image for w4
authored
49 my_first_committed_file my_third_committed_file
50 my_second_committed_file temp_file
eb1f383 @cbx33 Chap4 half way through
authored
51 john@satsuki:~/coderepo$ git branch wacky
52 john@satsuki:~/coderepo$ git branch
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
53 * master
54 wacky
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
55 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
56 \end{code}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
57
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
58 From looking at the output, it would appear that our \texttt{git branch wacky} command did not accomplish a whole lot.
59 Running the \indexgit{branch} command will give us a list of all branches in the repository.
60 You may have noticed the presence of the \texttt{*} in front of the word \texttt{master}.
61 This is telling us that we are on the branch called \textbf{master}.
62 Hang on though, did we not just create a new branch called \textbf{wacky}?
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
63
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
64 Well yes we did.
65 However we have not yet switched to it.
66 To do this, we use our good friend \texttt{git checkout}.
67 This will change the working copy to reflect the most recent commit in that branch, and will reset our HEAD accordingly, so that it points to this latest commit
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
68
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
69 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
70 john@satsuki:~/coderepo$ git checkout wacky
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
71 Switched to branch 'wacky'
eb1f383 @cbx33 Chap4 half way through
authored
72 john@satsuki:~/coderepo$ git branch
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
73 master
74 * wacky
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
75 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
76 \end{code}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
77
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
78 Now the \texttt{*} has moved to be in front of the word \texttt{wacky} and we have confirmation from the line above that we have in fact \texttt{Switched to branch 'wacky'}.
62c1481 Squash double-space
Johan Sageryd authored
79 Now we are here in wonderland, what can we do? Well, potentially anything we could do in our previous branch, but with the added benefit that we are separated.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
80 Some of you maybe be thinking, but we never created an initial branch called \textbf{master}.
81 Whilst this is true in one sense, the \texttt{git init} command actually created this branch for us when we initialised the repository.
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
82
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
83 We will start off by taking a deeper look at what is present in our branch.
84 Running a \texttt{git log} shows us the history of our branch.
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
85
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
86 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
87 john@satsuki:~/coderepo$ git log
88 commit a022d4d1edc69970b4e8b3fe1da3dccd943a55e4
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
89 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
90 Date: Thu Mar 31 22:05:55 2011 +0100
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
91
92 Messed with a few files
93
eb1f383 @cbx33 Chap4 half way through
authored
94 commit 9938a0c30940dccaeddce4bb2eb151fba3a21ae5
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
95 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
96 Date: Thu Mar 31 20:34:23 2011 +0100
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
97
98 Finished adding initial files
99
eb1f383 @cbx33 Chap4 half way through
authored
100 commit 163f06147a449e724d0cfd484c3334709e8e1fce
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
101 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
102 Date: Thu Mar 31 20:32:59 2011 +0100
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
103
104 Made a few changes to first and second files
105
eb1f383 @cbx33 Chap4 half way through
authored
106 commit cfe23cbe0150fda69a004e301828097935ec4397
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
107 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
108 Date: Thu Mar 31 20:27:44 2011 +0100
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
109
110 My First Ever Commit
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
111 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
112 \end{code}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
113
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
114 You may notice here that the log messages being displayed are identical to that which we had before in our \textbf{master} branch.
115 This is nothing to be worried about.
116 You may be wondering how these can be present if we are in a totally separate environment.
117 Well, though we have branched, the history that led us to this point is the same.
118 As we have not made any changes yet, we do not notice any divergence.
119 If we now make changes to the \emph{repository} we can take a look and see how this will affect things.
120 To start with, let us remove a few files from the working tree, commit these actions, then add a few more, stage them and commit the new files.
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
121
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
122 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
123 john@satsuki:~/coderepo$ git rm my_first_committed_file
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
124 rm 'my_first_committed_file'
eb1f383 @cbx33 Chap4 half way through
authored
125 john@satsuki:~/coderepo$ git rm my_second_committed_file
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
126 rm 'my_second_committed_file'
eb1f383 @cbx33 Chap4 half way through
authored
127 john@satsuki:~/coderepo$ git commit -m 'Removed a few files'
128 [wacky 4a155e4] Removed a few files
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
129 2 files changed, 0 insertions(+), 2 deletions(-)
130 delete mode 100644 my_first_committed_file
131 delete mode 100644 my_second_committed_file
eb1f383 @cbx33 Chap4 half way through
authored
132 john@satsuki:~/coderepo$ echo "A new file" > newfile1
133 john@satsuki:~/coderepo$ echo "Another new file" > newfile2
134 john@satsuki:~/coderepo$ git add newfile*
135 john@satsuki:~/coderepo$ git commit -m 'Added two new files'
136 [wacky 55fb69f] Added two new files
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
137 2 files changed, 2 insertions(+), 0 deletions(-)
138 create mode 100644 newfile1
139 create mode 100644 newfile2
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
140 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
141 \end{code}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
142
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
143 \index{Linux commands!ls}So we have made two new commits to the repository under our new branch.
144 If we run a Linux \texttt{ls} command to see the files which are in the working tree, we can see that our working copy has indeed altered.
145 We will also use our \texttt{git log} tool to see what the latest commit is.
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
146
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
147 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
148 john@satsuki:~/coderepo$ ls
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
149 my_third_committed_file newfile1 newfile2 temp_file
eb1f383 @cbx33 Chap4 half way through
authored
150 john@satsuki:~/coderepo$ git log -n1
151 commit 55fb69f4ad26fdb6b90ac6f43431be40779962dd
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
152 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
153 Date: Fri Apr 1 00:10:49 2011 +0100
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
154
155 Added two new files
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
156 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
157 \end{code}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
158
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
159 Brilliant.
160 As you can see, we have used \texttt{git log} in a slightly different way to limit the number of commits.
161 This is what the \texttt{-n} parameter is used for.
62c1481 Squash double-space
Johan Sageryd authored
162 However, what happens if we go back to the \textbf{master} branch again? In theory we should have everything back the way we left it just before creating the branch.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
163 Let's move back into our \textbf{master} branch and examine the state of play.
e4ef43f @cbx33 Added new image for w4
authored
164
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
165 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
166 john@satsuki:~/coderepo$ git checkout master
e4ef43f @cbx33 Added new image for w4
authored
167 Switched to branch 'master'
eb1f383 @cbx33 Chap4 half way through
authored
168 john@satsuki:~/coderepo$ ls
e4ef43f @cbx33 Added new image for w4
authored
169 my_first_committed_file my_third_committed_file
170 my_second_committed_file temp_file
eb1f383 @cbx33 Chap4 half way through
authored
171 john@satsuki:~/coderepo$ git log -n1
172 commit a022d4d1edc69970b4e8b3fe1da3dccd943a55e4
e4ef43f @cbx33 Added new image for w4
authored
173 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
174 Date: Thu Mar 31 22:05:55 2011 +0100
e4ef43f @cbx33 Added new image for w4
authored
175
176 Messed with a few files
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
177 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
178 \end{code}
e4ef43f @cbx33 Added new image for w4
authored
179
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
180 Comparing that to our previous \texttt{ls} command, we can see that this is exactly what the working tree looked like at the beginning of the chapter.
181 Let us take a look at a diagram of the commit history to see what has happened in our repository.
e4ef43f @cbx33 Added new image for w4
authored
182
c0faf01 @cbx33 More changes from the book proof (physical)
authored
183 \figuregith{7cm}{images/f-w4-d1.pdf}{Our first branch}
112170d @cbx33 Added more to chap 4 to describe how to branch
authored
184
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
185 \index{pointers}So there are really two pointers in our repository at the moment, from a branch point of view.
f70bb77 @cbx33 Removed cleardoublepage and fixed a slight typo in chap4
authored
186 One of them points to commit \textbf{a022d4d\ldots} and is called \textbf{master}.
187 The other is called \textbf{wacky} and points to \textbf{55fb69f\ldots}.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
188 At this point you may be thinking that branches are pretty much the same thing as tags.
189 Well, they are except for one important fact.
190 We are going to use our \texttt{git branch} command, with a new parameter, to show us the difference.
191 Take a look at the output of the following operations.
192 We have pruned the output of the \texttt{git show} command for brevity.
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
193
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
194 \begin{code}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
195 john@satsuki:~/coderepo$ git checkout wacky
eb1f383 @cbx33 Chap4 half way through
authored
196 Switched to branch 'wacky'
197 john@satsuki:~/coderepo$ git branch -v
198 master a022d4d Messed with a few files
199 * wacky 55fb69f Added two new files
200 john@satsuki:~/coderepo$ git tag v2.0
201 john@satsuki:~/coderepo$ git show v2.0
202 commit 55fb69f4ad26fdb6b90ac6f43431be40779962dd
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
203 ...
204 ...
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
205 \end{code}
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
206
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
207 So here we have added a tag in our current branch, \textbf{wacky}, and we can see that the commit ID for the tag \textbf{v2.0} points \textbf{55fb69f}.
208 We can also see that the branch \textbf{wacky} is currently pointing to the same commit ID, \textbf{55fb69f}.
209 Now let us add another file in, make a commit and see what happens after this.
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
210
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
211 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
212 john@satsuki:~/coderepo$ echo "New stuff" > another_file
213 john@satsuki:~/coderepo$ git add another_file
214 john@satsuki:~/coderepo$ git commit -m 'Added another file'
215 [wacky 9710177] Added another file
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
216 1 files changed, 1 insertions(+), 0 deletions(-)
217 create mode 100644 another_file
eb1f383 @cbx33 Chap4 half way through
authored
218 john@satsuki:~/coderepo$ git show v2.0
219 commit 55fb69f4ad26fdb6b90ac6f43431be40779962dd
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
220 ...
221 ...
eb1f383 @cbx33 Chap4 half way through
authored
222 john@satsuki:~/coderepo$ git branch -v
223 master a022d4d Messed with a few files
224 * wacky 9710177 Added another file
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
225 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
226 \end{code}
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
227
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
228 How interesting.
229 The difference between tags and branches now becomes pretty clear.
230 Whilst a tag always points to the same commit, a branch reference always points to the tip of that branch.
231 In essence the reference that a branch points to moves as subsequent commits are made.
232 By doing this, the whole history of the branch can be retraced.
233 Since we know the latest commit, we also know the parent of that commit and so on and so on.
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
234
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
235 Since a branch is just a pointer to a commit, performing operations like adding, modifying and deleting files in the repository can be done safely, without destroying any data in another branch.
236 In short, it will allow us to completely redesign whatever is being stored in the current branch without worrying about how it will affect our baseline.
237 For a developer, this is pretty crucial stuff.
238 This gives people the chance to play with their data and experiment, which is often where the greatest ideas come from.
56372b2 @cbx33 Added some more to Ch4 and a few topics
authored
239
ae10c38 @cbx33 Updated TODO.topics
authored
240 \section{Day 2 - ``Branches galore''}
241 \subsection{Working with branches}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
242 Now we know about branches in general, we should really learn about how to merge changes from one branch into another.
243 Branches are fantastic for trying new things out and testing ideas, but if those ideas are successful, we need a way of pulling those changes into our \textbf{master} branch.
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
244
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
245 Of course we could do this the old fashioned way.
246 We could switch into our \textbf{wacky} branch, do a little development, copy the files somewhere else, switch to our \textbf{master} branch, and paste the files over the top.
247 Now, this is probably the simplest way of merging possible.
248 In actual fact, this is not really merging at all.
249 However one thing that would be lost is the history of how that branch has developed over time.
250 Sometimes this can be crucial for knowing why certain things were changed during the development process.
ae10c38 @cbx33 Updated TODO.topics
authored
251
a77cdf2 Fix speling
Johan Sageryd authored
252 \index{merging}Let us take a little look at the command output of a simple merge, explain it a little, and then look at a diagrammatic representation.
ae10c38 @cbx33 Updated TODO.topics
authored
253
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
254 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
255 john@satsuki:~/coderepo$ git branch
ae10c38 @cbx33 Updated TODO.topics
authored
256 master
257 * wacky
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
258 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
259 \end{code}
ae10c38 @cbx33 Updated TODO.topics
authored
260
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
261 Firstly we check just to see what branch we are on.
262 Next we checkout the branch we want our development branch to be merged into.
263 In this case, we want to merge \textbf{wacky} into \textbf{master} and so we must first checkout the \textbf{master} branch.
264 Then we can merge in the changes from our \textbf{wacky} branch.
ae10c38 @cbx33 Updated TODO.topics
authored
265
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
266 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
267 john@satsuki:~/coderepo$ git checkout master
ae10c38 @cbx33 Updated TODO.topics
authored
268 Switched to branch 'master'
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
269 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
270 \end{code}
ae10c38 @cbx33 Updated TODO.topics
authored
271
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
272 Now we can run the actual merge.
ae10c38 @cbx33 Updated TODO.topics
authored
273
8de6136 @cbx33 Indexing chap4 and after hours 4
authored
274 \index{merging!fast-forward}
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
275 \begin{code}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
276 john@satsuki:~/coderepo$ git merge wacky
eb1f383 @cbx33 Chap4 half way through
authored
277 Updating a022d4d..9710177
ae10c38 @cbx33 Updated TODO.topics
authored
278 Fast-forward
279 another_file | 1 +
280 my_first_committed_file | 1 -
281 my_second_committed_file | 1 -
282 newfile1 | 1 +
283 newfile2 | 1 +
284 5 files changed, 3 insertions(+), 2 deletions(-)
285 create mode 100644 another_file
286 delete mode 100644 my_first_committed_file
287 delete mode 100644 my_second_committed_file
288 create mode 100644 newfile1
289 create mode 100644 newfile2
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
290 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
291 \end{code}
ae10c38 @cbx33 Updated TODO.topics
authored
292
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
293 We can see that the first line after our \indexgit{merge} command shows us which commit \textbf{master} is the latest common ancestor to both branches and then which commit is the last in our new branch.
294 In this case we are merging from \textbf{a022d4d} to \textbf{9710177}.
295 The line below this is even more important.
296 This type of merge is called a \emph{fast-forward} merge.
297 We have not made any changes to our \textbf{master} branch since we began developing and subsequently, after finishing our development work, we literally only require fast-forwarding the \textbf{master} branch to the same point in time as our \textbf{wacky} one.
298 Beneath this text, we see more information about just what is included in the merge.
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
299
300 We are going to perform a quick check, to see that we are in fact on the master branch and that the latest log message is the one from the point we last left the \textbf{wacky} branch.
ae10c38 @cbx33 Updated TODO.topics
authored
301
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
302 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
303 john@satsuki:~/coderepo$ git log -n1
304 commit 9710177657ae00665ca8f8027b17314346a5b1c4
b95343f @cbx33 Changed code authors
authored
305 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
eb1f383 @cbx33 Chap4 half way through
authored
306 Date: Fri Apr 1 00:16:17 2011 +0100
ae10c38 @cbx33 Updated TODO.topics
authored
307
308 Added another file
eb1f383 @cbx33 Chap4 half way through
authored
309 john@satsuki:~/coderepo$ git branch
ae10c38 @cbx33 Updated TODO.topics
authored
310 * master
311 wacky
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
312 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
313 \end{code}
ae10c38 @cbx33 Updated TODO.topics
authored
314
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
315 Now let us take a quick look at a diagram to see how this change actually affected the commit flow.
316 We have included tags in this diagram, so that you can see where they point to as well.
ae10c38 @cbx33 Updated TODO.topics
authored
317
c0faf01 @cbx33 More changes from the book proof (physical)
authored
318 \figuregith{7cm}{images/f-w4-d2.pdf}{Our first merge}
1f555a1 @cbx33 Added new image for week 4
authored
319
8de6136 @cbx33 Indexing chap4 and after hours 4
authored
320 \index{tagging!difference to branch}\index{branching!difference to tags}This picture should make it clear that the fundamental difference between tags and branches is that whilst the pointer to a branch moves with each commit to that branch, a tag points to a single commit only and never changes, unless forcibly so by the user.
1f555a1 @cbx33 Added new image for week 4
authored
321
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
322 There are a number of tricks that we can employ when using branches.
323 They are possible because of the super flexible way in which branches are implemented in Git.
324 As a branch is literally a pointer to a commit, certain operations are available to a user that other systems just can not implement.
325 However, we should point something out at this point.
326 Even though we have not yet made any of our repositories public or available to other people, something should always be in the back of your mind.
327 Allow a few minutes to read the next few paragraphs below.
328
62c1481 Squash double-space
Johan Sageryd authored
329 As someone once said, ``With great power, comes great responsibility.'' Git is hugely powerful.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
330 However, with this power comes a certain level of responsibility.
331 We are referring here to Git's ability to change history.
332 If you have watched any science fiction films involving time travel, you should be aware of the difficulties and problems often associated with time travel.
333 In Git, the same rule applies and the basics of the rule boil down to this: \textbf{If you have made a commit, or path of commits available, you should never ever change anything in the history of those commits or the commits themselves.}
334
335 If you are wondering why this is so important, consider this.
336 If you are making a series of films, and you have already released the first two of a trilogy, you would not put elements in the third one that contradict the history of the others.
337 You can not just act like the history of the first two did not happen.
62c1481 Squash double-space
Johan Sageryd authored
338 Occasionally this happens in the film industry and what is the reaction of the public? People get mad.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
339 Sometimes very mad.
340 This is what will happen if you do the same with Git.
341 People who are using your repository will end up with many problems and inconsistencies.
342 \textbf{Do NOT do it, ever}.
343 There are ways to revert certain behaviour and we will cover this at a later stage.
344
345 Having said this, you should not shy away from the awesome capabilities of Git.
346 We are going to cover a few situations now which you may find yourself in.
347 Some of them do alter history, some of them do not.
348 This is why it is important to have an understanding of how Git works.
349 It can be your best friend, but it can also cause you issues.
350 If you take the time to tame the beast, it will be one of the most awesome tools in your developers tool bag and can save your life time and time again.
e2dafbf @cbx33 Added warning
authored
351
266f6fe @cbx33 Added new details to chap4
authored
352 \begin{trenches}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
353 ``Oh man.'' The familiar cry of Simon needing something reverberated round the office.
354 Rob could never understand why he didn't ask for help.
355 Simon would sit there wallowing out loud until someone could take it no longer and would eventually go over and help him.
266f6fe @cbx33 Added new details to chap4
authored
356
357 ``What to do\ldots what to do.''
358
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
359 Rob could take it no more.
360 Simon had been exclaiming now for about five minutes and Rob seemed to either be the only one who wasn't listening to music, or who was getting annoyed.
361 He rolled his eyes, ``What's up Si?''
266f6fe @cbx33 Added new details to chap4
authored
362
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
363 Simon grinned inanely to himself.
1ca454d Tidy up dialogue lines
Johan Sageryd authored
364 ``I just started modifying some files and well \ldots I don't want to get rid of them \ldots I'm not 100\% sure what I've changed. I wish I had started this in a new branch.''
266f6fe @cbx33 Added new details to chap4
authored
365
366 ``Well, when did you last commit?''
367
368 ``Just before I started all this work,'' came the reply.
369
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
370 Rob pointed at Simon's screen.
1ca454d Tidy up dialogue lines
Johan Sageryd authored
371 ``You can just create a new branch now and move all the changes into it in one go. You can do it in one command actually.''
266f6fe @cbx33 Added new details to chap4
authored
372 \end{trenches}
373
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
374 It is one hundred percent true.
375 How many times have you been working on something and wished that you could move all the changes you had made to a new safe environment to protect your already good, working code.
376 Well, the new safe environment we spoke of sounds suspiciously like a branch.
377 In Git, any changes you have in your working copy can be taken into a new branch by issuing one command.
378 It is important to note that these changes can also be taken into an existing branch, but you may run into problems if those changes conflict with items already in that branch.
e2dafbf @cbx33 Added warning
authored
379
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
380 \index{branching}For now let us see how we can take our working copy changes into a new branch to continue development of some wonderful new feature.
381 We are going to start by making some changes to our newfiles.
0e6dddf @cbx33 Finished branch example #1
authored
382
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
383 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
384 john@satsuki:~/coderepo$ echo "and some more changes" >> newfile1
385 john@satsuki:~/coderepo$ echo "and a new feature" >> newfile2
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
386 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
387 \end{code}
0e6dddf @cbx33 Finished branch example #1
authored
388
389 Now we are going to make a new branch and switch into it.
390
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
391 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
392 john@satsuki:~/coderepo$ git checkout -b wonderful
0e6dddf @cbx33 Finished branch example #1
authored
393 M newfile1
394 M newfile2
395 Switched to a new branch 'wonderful'
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
396 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
397 \end{code}
0e6dddf @cbx33 Finished branch example #1
authored
398
62c1481 Squash double-space
Johan Sageryd authored
399 Did you see that? We managed to create a new branch and move into it in one go.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
400 The \texttt{git checkout} command is usually what we would use to move into a branch, not create it.
401 When we use the \texttt{-b} parameter, the \texttt{git checkout} command can be used to create a new branch and switch to it in one go.
402 Notice we have chosen the name \textbf{wonderful} for this particular branch.
403 There is also a status output below this that shows we have pulled two modifications into this branch, denoted by the letter \texttt{M} in front of the file name.
0e6dddf @cbx33 Finished branch example #1
authored
404
405 Now we can commit these changes.
406
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
407 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
408 john@satsuki:~/coderepo$ git commit -a -m 'Fantastic new feature'
409 [wonderful cfbecab] Fantastic new feature
0e6dddf @cbx33 Finished branch example #1
authored
410 2 files changed, 2 insertions(+), 0 deletions(-)
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
411 john@satsuki:~/coderepo$ git diff master wonderful
0e6dddf @cbx33 Finished branch example #1
authored
412 diff --git a/newfile1 b/newfile1
413 index 24e7dfa..ef20984 100644
414 --- a/newfile1
415 +++ b/newfile1
416 @@ -1 +1,2 @@
417 A new file
418 +and some more changes
419 diff --git a/newfile2 b/newfile2
420 index cba16cc..dac4357 100644
421 --- a/newfile2
422 +++ b/newfile2
423 @@ -1 +1,2 @@
424 Another new file
425 +and a new feature
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
426 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
427 \end{code}
0e6dddf @cbx33 Finished branch example #1
authored
428
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
429 After running the diff, we can see the differences between the \textbf{master} and the \textbf{wonderful} branches.
430 Looking more closely at the hunks, the only differences between the two branches are those that we made before we created our \textbf{wonderful} branch.
431 We have achieved what we set out to in bringing uncommitted changes from \textbf{master} into \textbf{wonderful} and subsequently committing them.
6af4fa0 @cbx33 Changed to pete in code
authored
432
87f8677 @cbx33 Finished talking about deleting branches
authored
433 \section{Day 3 - ``Tricking the twigs''}
434 \subsection{More neat ways to work with branches}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
435 This is only the beginning of the fantastic feature set that Git offers.
436 By knowing how Git handles your data, you can make it work for you.
437 Let us take a look at another situation you may find yourself in.
6af4fa0 @cbx33 Changed to pete in code
authored
438
439 \begin{trenches}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
440 ``Rob!'' shouted Simon for the fourth time that morning.
441 ``Rob, I made a real boo boo this time.''
6af4fa0 @cbx33 Changed to pete in code
authored
442
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
443 Rob walked over to Simon again, head lolling back on his shoulders and his eyes rolling.
444 His arms weighed heavily by his side and his walk reminded Simon of that of a zombie.
6af4fa0 @cbx33 Changed to pete in code
authored
445
446 ``What have you done THIS time?'' asked the developer as he reached the desk.
447
1ca454d Tidy up dialogue lines
Johan Sageryd authored
448 Simon drew in his breath deeply, ``Well, I created a branch, started working away, committing like a good'un, but I only just realised I'm on the wrong branch. I forgot to switch.''
449 He hung his head in shame.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
450 ``I'm screwed right?''
6af4fa0 @cbx33 Changed to pete in code
authored
451
452 ``Not necessarily,'' replied his colleague.
453 \end{trenches}
454
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
455 This wouldn't work in all situations, but then there are other techniques described later in the book to deal with more special cases.
456 In this scenario we have created a branch, forgotten to switch into it, and carried on committing as if we were in our new branch.
457 At first glance it may seem as if we are stuck.
62c1481 Squash double-space
Johan Sageryd authored
458 Once we have committed, we can't undo those commits right? Well, that's not entirely accurate.
6af4fa0 @cbx33 Changed to pete in code
authored
459
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
460 We actually have two ways of clearing up this particular situation.
461 The first of these is to use \indexgit{revert} to undo the changes of each commit.
462 Whilst this will work, we have two problems, a) we do not know how to use the \texttt{git revert} tool yet, and b) we can actually handle this situation much more cleanly.
463 We are going to make a new branch, make a few commits and then look at a diagram of our recent work to see how we can work things out.
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
464
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
465 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
466 john@satsuki:~/coderepo$ git checkout master
467 Already on 'master'
468 john@satsuki:~/coderepo$ git branch zaney
469 john@satsuki:~/coderepo$ echo "and some awesome changes" >> newfile1
470 john@satsuki:~/coderepo$ git commit -a -m 'Made an awesome change'
471 [master a27d49e] Made an awesome change
51787a4 @cbx33 Added code for reset stage
authored
472 1 files changed, 1 insertions(+), 0 deletions(-)
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
473 john@satsuki:~/coderepo$ echo "and some more awesome changes" >>
1518cba @cbx33 Updates to chapter 4
authored
474 newfile2
eb1f383 @cbx33 Chap4 half way through
authored
475 john@satsuki:~/coderepo$ git commit -a -m 'Made another awesome change'
476 [master 7cc32db] Made another awesome change
51787a4 @cbx33 Added code for reset stage
authored
477 1 files changed, 1 insertions(+), 0 deletions(-)
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
478 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
479 \end{code}
6bf43e7 @cbx33 Updated commit message in image 2
authored
480
4321984 @cbx33 Removed figuregit for figuregith
authored
481 \figuregith{9cm}{images/f-w4-d3.pdf}{Repository including the mistake}
6bf43e7 @cbx33 Updated commit message in image 2
authored
482
4321984 @cbx33 Removed figuregit for figuregith
authored
483 \figuregith{9cm}{images/f-w4-d4.pdf}{Repository showing how things \emph{should} look}
6bf43e7 @cbx33 Updated commit message in image 2
authored
484
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
485 Figure 3 shows how our repository looks now, whereas Figure 4 shows how the repository should have looked if we had performed it properly.
486 You should notice that the positions of \texttt{master} and \texttt{zaney} have switched places.
a77cdf2 Fix speling
Johan Sageryd authored
487 How can we rectify this?
6bf43e7 @cbx33 Updated commit message in image 2
authored
488
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
489 We already discussed one method using \texttt{git revert}, which we are due to cover a little later.
490 However, because of the way that the history has been written, we can do something very simple.
491 We are going do the following the following steps.
51787a4 @cbx33 Added code for reset stage
authored
492
6bf43e7 @cbx33 Updated commit message in image 2
authored
493 \begin{enumerate}
494 \item Switch to our \textbf{zaney} branch
2f27f13 @cbx33 Added about reset
authored
495 \item Fast-forward our zaney branch so that it points to the same commit using a merge
6bf43e7 @cbx33 Updated commit message in image 2
authored
496 \item Switch back to our \textbf{master} branch
497 \item Reset our master branch back to the required point in time
498 \end{enumerate}
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
499
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
500 So let us take a look at the command line output and see how we achieve this.
501 Hopefully you should be familiar with most of the commands.
2f27f13 @cbx33 Added about reset
authored
502
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
503 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
504 john@satsuki:~/coderepo$ git checkout zaney
2f27f13 @cbx33 Added about reset
authored
505 Switched to branch 'zaney'
eb1f383 @cbx33 Chap4 half way through
authored
506 john@satsuki:~/coderepo$ git merge master
507 Updating 9710177..7cc32db
2f27f13 @cbx33 Added about reset
authored
508 Fast-forward
509 newfile1 | 1 +
510 newfile2 | 1 +
511 2 files changed, 2 insertions(+), 0 deletions(-)
eb1f383 @cbx33 Chap4 half way through
authored
512 john@satsuki:~/coderepo$ git checkout master
2f27f13 @cbx33 Added about reset
authored
513 Switched to branch 'master'
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
514 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
515 \end{code}
2f27f13 @cbx33 Added about reset
authored
516
c0faf01 @cbx33 More changes from the book proof (physical)
authored
517 Now we reach step four in our set of instructions.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
518 The one function we do not know how to perform yet is the resetting of our branch back to a previous point in time.
519 The point we need to rewind back to is the point that we initially created the \textbf{zaney} branch at.
520 We could have gotten this information by using \texttt{git log}.
521 Instead, this time we can use the information presented in the merge output to show the common ancestor, which has to be the point that we created our branch at.
522 In this case it is commit \textbf{9710177}.
2f27f13 @cbx33 Added about reset
authored
523
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
524 We are now going to perform the last step using an old friend called \texttt{git reset}.
525 You may be thinking that \texttt{git reset} is only used to reset files in the index, but in fact, \texttt{git reset} can actually perform many more tasks.
526 We are going to use it with the \texttt{--hard} option.
527 This option can be dangerous, as it will discard all modifications in the working tree, so use with caution.
528 If we had uncommitted changes in our repository at this point, we could not have used this option.
529 Let's use the command and see where we get.
2f27f13 @cbx33 Added about reset
authored
530
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
531 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
532 john@satsuki:~/coderepo$ git reset --hard 9710177
533 HEAD is now at 9710177 Added another file
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
534 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
535 \end{code}
2f27f13 @cbx33 Added about reset
authored
536
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
537 As you can see, we are told that the HEAD of our master branch is now at commit \textbf{9710177}.
538 \index{rewinding}We have successfully rewound our \textbf{master} branch to a previous state.
539 The \texttt{--hard} parameter reset the index and the working tree to be at the state of the commit we tell it to.
540 It disregards all working copy and staged modifications, so use it with care.
2f27f13 @cbx33 Added about reset
authored
541
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
542 The \texttt{git reset} command does not only work for rewinding back in time.
543 It can also be used to move a branch forward in time.
a77cdf2 Fix speling
Johan Sageryd authored
544 As an example of this, we used a fast-forward merge to move our \textbf{zaney} branch forward to be in-line with master.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
545 We could just have easily used \texttt{git reset --hard 7cc32db} from within the zaney branch, to bring it to the same point as the master.
546 In fact, though it looks scary, we could also have used \texttt{git reset --hard master} to reset the \textbf{zaney} branch to be at the same point as \textbf{master}.
547 Saves typing out those horrid commits does it not?
2f27f13 @cbx33 Added about reset
authored
548
549 Finally we are going to introduce one more use of the \texttt{git log} command to show us how our repository looks in a semi-graphical way.
550
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
551 \begin{code}
acbbb4e @cbx33 Line ending fudging in chap4
authored
552 john@satsuki:~/coderepo$ git log --graph --pretty=oneline --all --abbrev-commit --decorate
eb1f383 @cbx33 Chap4 half way through
authored
553 * 7cc32db (zaney) Made another awesome change
554 * a27d49e Made an awesome change
555 | * cfbecab (wonderful) Fantastic new feature
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
556 |/
eb1f383 @cbx33 Chap4 half way through
authored
557 * 9710177 (HEAD, wacky, master) Added another file
558 * 55fb69f (v2.0) Added two new files
559 * 4a155e4 Removed a few files
560 * a022d4d (tag: v1.0b, v1.0a) Messed with a few files
561 * 9938a0c Finished adding initial files
562 * 163f061 (v0.9) Made a few changes to first and second files
563 * cfe23cb My First Ever Commit
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
564 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
565 \end{code}
2f27f13 @cbx33 Added about reset
authored
566
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
567 \index{graphing}The \texttt{--graph} parameter, tells Git to draw a graph down the left hand column.
568 The \texttt{--pretty=oneline} parameter reduces the commit details to one line, else we see the entire log message of the commit.
569 \texttt{--all} shows all branches.
570 The \texttt{abbrev-commit} in the command tells Git to abbreviate the commit IDs to a sensible length.
571 Finally, \texttt{--decorate} shows us the tag and branch references.
572 Hopefully if you compare this tree to the diagram earlier, you will see that the tree is actually completely in order.
2f27f13 @cbx33 Added about reset
authored
573
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
574 Be aware that during this work we have changed the history of at least one of our branches.
575 Had we pushed our changes to a public server, which is something that will be discussed next week, we would have to force these changes to be accepted at the server end.
576 Git knows we are trying to change a past that may have been viewed by others and will warn us accordingly.
2f27f13 @cbx33 Added about reset
authored
577
87f8677 @cbx33 Finished talking about deleting branches
authored
578 \section{Day 4 - ``I pressed delete...''}
352830e @cbx33 Some minor changes
authored
579 \subsection{Handling the pressure}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
580 \index{branching!deleting}\index{branching!recovering}We have had some awesome fun working with branches, and hopefully you can see how utterly powerful Git is.
581 Sometimes though we can get ourselves into trouble and it is here that Git can also come to our rescue.
582 Let us learn how to delete a branch.
583 We are going to delete our \textbf{wacky} branch now as we have already merged it and no longer require it.
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
584
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
585 \begin{code}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
586 john@satsuki:~/coderepo$ git branch -d zaney
87f8677 @cbx33 Finished talking about deleting branches
authored
587 error: The branch 'zaney' is not fully merged.
588 If you are sure you want to delete it, run 'git branch -D zaney'.
eb1f383 @cbx33 Chap4 half way through
authored
589 john@satsuki:~/coderepo$ git branch -D zaney
590 Deleted branch zaney (was 7cc32db).
591 john@satsuki:~/coderepo$ git branch -v
592 * master 9710177 Added another file
593 wacky 9710177 Added another file
594 wonderful cfbecab Fantastic new feature
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
595 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
596 \end{code}
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
597
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
598 Ooops.
599 Despite the firm warning from Git, we have inadvertently deleted the \textbf{zaney} branch by mistake.
600 This does happen.
62c1481 Squash double-space
Johan Sageryd authored
601 When people are in the thick of it, they do make mistakes and it is comforting to know that Git is able to recover from this, but how? We have deleted the branch reference that pointed to the commit that was at the tip of the \textbf{zaney} branch by using the \texttt{-d} and \texttt{-D} parameters.
602 So the question is, does that commit still exist any more? Maybe we did more damage than we thought.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
603 By deleting all references to the commit, how do we get it back?
87f8677 @cbx33 Finished talking about deleting branches
authored
604
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
605 All is most definitely not lost.
606 Even though we have removed all references to the commits in question, they still exist in the repository.
3d8fe55 @dsas Fix minor wording/typos
dsas authored
607 They will continue to do so unless we run a clean up on the repository, which will be covered later, or if the items are left to age for more than at least fourteen days.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
608 This means that we have up to two weeks to try to recover the lost commits.
609 Of course in practice one would hope that we would perform the recovery much earlier than that.
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
610
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
611 We already know the commit ID that the branch was pointing to.
612 Git has been very kind and told us it, just before it carried out the delete.
613 We are looking for commit \textbf{7cc32db}.
614 If we run the command below, we will create and recover our branch in one go.
87f8677 @cbx33 Finished talking about deleting branches
authored
615
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
616 \begin{code}
eb1f383 @cbx33 Chap4 half way through
authored
617 john@satsuki:~/coderepo$ git branch zaney 7cc32db
618 john@satsuki:~/coderepo$ git branch -v
619 * master 9710177 Added another file
620 wacky 9710177 Added another file
621 wonderful cfbecab Fantastic new feature
622 zaney 7cc32db Made another awesome change
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
623 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
624 \end{code}
87f8677 @cbx33 Finished talking about deleting branches
authored
625
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
626 Our branch has been restored and points to the same place as it did before we deleted it.
627 As each commit points to its parent, we now have the complete history of \textbf{zaney} restored and the branch can be used as normal.
628 To complete this action, let us delete the \textbf{wacky} branch as originally intended.
87f8677 @cbx33 Finished talking about deleting branches
authored
629
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
630 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
631 john@satsuki:~/coderepo$ git branch -d wacky
632 Deleted branch wacky (was 9710177).
633 john@satsuki:~/coderepo$ git branch -v
634 * master 9710177 Added another file
635 wonderful cfbecab Fantastic new feature
636 zaney 7cc32db Made another awesome change
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
637 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
638 \end{code}
87f8677 @cbx33 Finished talking about deleting branches
authored
639
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
640 As you can see, when we deleted \textbf{wacky} we were not warned about unmerged changes.
641 This is because the \textbf{wacky} branch is at the same point as the \textbf{master} branch.
0ff1742 @cbx33 Changed a lot of wording in chap4, later portion of file is a complet…
authored
642
2c6b38b @cbx33 Changed around some days
authored
643 \section{Day 5 - ``Conflicting information''}
644 \subsection{What to do when it all goes wrong}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
645 \index{conflicts}The team have been playing with branches for a few days now and are beginning to settle into the idea of branching often.
646 As you can see, in Git, a branch is a really simple device for allowing experimentation and development.
647 As the implementation of branches is so simple, it is also really fast to switch between branches.
648 If you have been keeping up with the \emph{After Hours} sections, you can hopefully see that when switching branches, Git only needs to alter what is different between one working copy and another.
c3a3b07 @cbx33 More stash information
authored
649
3b5f377 @jonasbb Forgotten to correct Week number after moving? Now number fixed.
jonasbb authored
650 Let us see what new issues the team runs into during Week 4.
c3a3b07 @cbx33 More stash information
authored
651
2c6b38b @cbx33 Changed around some days
authored
652 \begin{trenches}
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
653 ``Hmm,'' the puzzled noise reverberated round Klaus' corner of the office.
654 Mumbling commenced.
1ca454d Tidy up dialogue lines
Johan Sageryd authored
655 ``So if I did that, then why is that not \ldots I mean I didn't think \ldots that's probably the problem Klaus \ldots sill 'luser'.''
656 He chuckled to himself, hardly noticing the looming figure of John.
c3a3b07 @cbx33 More stash information
authored
657
2c6b38b @cbx33 Changed around some days
authored
658 ``You got a conflict,'' said John matter of factly.
c3a3b07 @cbx33 More stash information
authored
659
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
660 ``I can see that,'' came Klaus' reply.
661 ``The problem is how do I solve it''
c3a3b07 @cbx33 More stash information
authored
662
2c6b38b @cbx33 Changed around some days
authored
663 ``What were you doing?''
c3a3b07 @cbx33 More stash information
authored
664
2c6b38b @cbx33 Changed around some days
authored
665 ``Well I had a few branches I had been working on and I was trying to merge them in.''
c3a3b07 @cbx33 More stash information
authored
666
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
667 ``Figures,'' said John.
2c6b38b @cbx33 Changed around some days
authored
668 \end{trenches}
26bb99b @cbx33 Started talking about stash
authored
669
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
670 Conflicts are bound to happen at some point.
671 Even the best project processes in the world will sometimes end up with a conflict that has to be resolved.
672 We should, at this point, clarify what a conflict actually is.
673 A conflict occurs when an attempt is made to reconcile multiple changes to the same section of a file at the same time.
674 This usually means that the same line of code is modified by two different parties at the same time.
675 Now that we have several branches in our test repository, let us merge them back into master and see if we come up with a conflict.
2c6b38b @cbx33 Changed around some days
authored
676
22a3d66 @cbx33 Added more to chap4
authored
677 First we are going to add a little change to one of our files.
2c6b38b @cbx33 Changed around some days
authored
678
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
679 \begin{code}
acbbb4e @cbx33 Line ending fudging in chap4
authored
680 john@satsuki:~/coderepo$ echo "Another update to this file" >> my_third_committed_file
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
681 john@satsuki:~/coderepo$ git commit -a -m 'Updated third file'
682 [master 4ac9201] Updated third file
22a3d66 @cbx33 Added more to chap4
authored
683 1 files changed, 1 insertions(+), 0 deletions(-)
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
684 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
685 \end{code}
2c6b38b @cbx33 Changed around some days
authored
686
22a3d66 @cbx33 Added more to chap4
authored
687 Now let us merge in our \textbf{wonderful} branch.
4d63bff @cbx33 More on stashing
authored
688
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
689 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
690 john@satsuki:~/coderepo$ git merge wonderful
2c6b38b @cbx33 Changed around some days
authored
691 Merge made by recursive.
692 newfile1 | 1 +
693 newfile2 | 1 +
694 2 files changed, 2 insertions(+), 0 deletions(-)
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
695 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
696 \end{code}
22a3d66 @cbx33 Added more to chap4
authored
697
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
698 So far, our merge has gone pretty well.
699 We have taken all of the changes that were made in the \textbf{wonderful} branch and pulled them into our \textbf{master} branch.
700 If we wanted to, we could continue on making changes to the \textbf{wonderful} branch and we could keep pulling changes in from one to the other as time went by.
701 Figure 5 shows what our repository looks like now.
22a3d66 @cbx33 Added more to chap4
authored
702
c0faf01 @cbx33 More changes from the book proof (physical)
authored
703 \figuregith{11cm}{images/f-w4-d5.pdf}{Repository state after \textbf{wonderful} merge}
22a3d66 @cbx33 Added more to chap4
authored
704
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
705 Our repository tree looks a little strange now.
706 Notice that the most recent commit, \textbf{b119573}, has two parents.
62c1481 Squash double-space
Johan Sageryd authored
707 Can this be true? If we run our \texttt{git show} command against that commit ID, we see something new.
22a3d66 @cbx33 Added more to chap4
authored
708
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
709 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
710 john@satsuki:~/coderepo$ git show b119573
711 commit b119573f4508514c55e1c4e3bebec0ab3667d071
712 Merge: 4ac9201 cfbecab
e5074c6 @cbx33 Pete to John
authored
713 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
714 Date: Fri Apr 1 07:35:13 2011 +0100
22a3d66 @cbx33 Added more to chap4
authored
715
716 Merge branch 'wonderful'
717
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
718 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
719 \end{code}
22a3d66 @cbx33 Added more to chap4
authored
720
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
721 Notice the line \texttt{Merge: 4ac9201 cfbecab}, which simply tells us that this is a special type of commit, a merge commit.
722 When we previously performed a merge, the branch we were merging back into had not changed since we branched off and did our development work.
723 If you remember, we called this a \emph{fast-forward} merge, simply because we moved our \emph{destination} branch forwards to meet the tip of the development branch.
22a3d66 @cbx33 Added more to chap4
authored
724
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
725 \index{merging!non fast-forward}This time things are a little different.
726 During out development time on \textbf{wonderful}, something changed on \textbf{master}.
727 We did not make many alterations, but just the fact that we made some changed the way the merge was performed.
728 In fact, we can see this if we look at the first line after the merge.
729 Instead of indicating a \emph{fast-forward} merge, it now states that the merge was \emph{recursive}.
730 If you are interested in the different types of merge algorithms, you should read the \emph{After Hours} section for this chapter.
22a3d66 @cbx33 Added more to chap4
authored
731
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
732 So now the history of this latest commit actually relies on two previous commits.
733 The changes that have been introduced in these commits are merged together to form a combined tree of files.
734 This is the snapshot that is represented in commit \textbf{ba0bfc}.
22a3d66 @cbx33 Added more to chap4
authored
735
736 Let us now remove that third file before merging in the \textbf{zaney} branch.
737
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
738 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
739 john@satsuki:~/coderepo$ git rm my_third_committed_file
22a3d66 @cbx33 Added more to chap4
authored
740 rm 'my_third_committed_file'
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
741 john@satsuki:~/coderepo$ git commit -a -m 'Removed third file'
742 [master ed2301b] Removed third file
22a3d66 @cbx33 Added more to chap4
authored
743 1 files changed, 0 insertions(+), 2 deletions(-)
744 delete mode 100644 my_third_committed_file
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
745 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
746 \end{code}
22a3d66 @cbx33 Added more to chap4
authored
747
748 So now we are ready to merge in the \textbf{zaney} branch.
749
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
750 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
751 john@satsuki:~/coderepo$ git merge zaney
2c6b38b @cbx33 Changed around some days
authored
752 Auto-merging newfile1
753 CONFLICT (content): Merge conflict in newfile1
754 Auto-merging newfile2
755 CONFLICT (content): Merge conflict in newfile2
756 Automatic merge failed; fix conflicts and then commit the result.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
757 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
758 \end{code}
4d63bff @cbx33 More on stashing
authored
759
62c1481 Squash double-space
Johan Sageryd authored
760 Oh dear! That probably did not go as well as we had hoped.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
761 We have two conflicts.
762 The first is in \texttt{newfile1} and the second in \texttt{newfile2}.
763 You may be wondering why.
62c1481 Squash double-space
Johan Sageryd authored
764 The last commit we made did not make any changes to either of those files, so why do we suddenly have a conflict? When using a version control system like Git, conflicts are an every day part of life.
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
765 A conflict does not mean you have done something wrong.
766 It simply means that the automatic merging algorithm can not merge the changes.
2c6b38b @cbx33 Changed around some days
authored
767
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
768 In this case we have a conflict because the files have changed in both sides of the merge, since they diverged.
769 Rephrasing this slightly: Since the point when we created the branch \textbf{zaney}, at commit \textbf{55fb69}, both the \textbf{master} branch and the \textbf{zaney} branch have both modified the same files in the same places.
770 Right now, our merge is paused.
771 For now, let us abort the merge so that we can take a closer look at what happened.
2c6b38b @cbx33 Changed around some days
authored
772
8de6136 @cbx33 Indexing chap4 and after hours 4
authored
773 \index{merging!resetting}
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
774 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
775 john@satsuki:~/coderepo$ git reset --merge
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
776 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
777 \end{code}
9d50a72 @cbx33 Finished talking about merging
authored
778
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
779 So let us compare the changes between our latest common ancestor and our branch tips.
780 We will first look at the difference between the ancestor and our \textbf{master} branch, but limit it to the files with conflicts.
9d50a72 @cbx33 Finished talking about merging
authored
781
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
782 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
783 john@satsuki:~/coderepo$ git diff 55fb69 master -- newfile*
9d50a72 @cbx33 Finished talking about merging
authored
784 diff --git a/newfile1 b/newfile1
785 index 24e7dfa..ef20984 100644
786 --- a/newfile1
787 +++ b/newfile1
788 @@ -1 +1,2 @@
789 A new file
790 +and some more changes
791 diff --git a/newfile2 b/newfile2
792 index cba16cc..dac4357 100644
793 --- a/newfile2
794 +++ b/newfile2
795 @@ -1 +1,2 @@
796 Another new file
797 +and a new feature
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
798 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
799 \end{code}
9d50a72 @cbx33 Finished talking about merging
authored
800
801 Now we will do the same between the common ancestor and the tip of \textbf{zaney}.
802
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
803 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
804 john@satsuki:~/coderepo$ git diff 55fb69 zaney -- newfile*
9d50a72 @cbx33 Finished talking about merging
authored
805 diff --git a/newfile1 b/newfile1
806 index 24e7dfa..d94dacc 100644
807 --- a/newfile1
808 +++ b/newfile1
809 @@ -1 +1,2 @@
810 A new file
811 +and some awesome changes
812 diff --git a/newfile2 b/newfile2
813 index cba16cc..45659d7 100644
814 --- a/newfile2
815 +++ b/newfile2
816 @@ -1 +1,2 @@
817 Another new file
818 +and some more awesome changes
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
819 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
820 \end{code}
9d50a72 @cbx33 Finished talking about merging
authored
821
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
822 So hopefully you can see that we have tried to change the second line in both files.
823 This is where the conflict is arising from.
824 Let us try to run the merge again and this time we will resolve the conflicts manually.
9d50a72 @cbx33 Finished talking about merging
authored
825
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
826 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
827 john@satsuki:~/coderepo$ git merge zaney
9d50a72 @cbx33 Finished talking about merging
authored
828 Auto-merging newfile1
829 CONFLICT (content): Merge conflict in newfile1
830 Auto-merging newfile2
831 CONFLICT (content): Merge conflict in newfile2
832 Automatic merge failed; fix conflicts and then commit the result.
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
833 john@satsuki:~/coderepo$ cat newfile1
9d50a72 @cbx33 Finished talking about merging
authored
834 A new file
835 <<<<<<< HEAD
836 and some more changes
837 =======
838 and some awesome changes
839 >>>>>>> zaney
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
840 john@satsuki:~/coderepo$ cat newfile2
9d50a72 @cbx33 Finished talking about merging
authored
841 Another new file
842 <<<<<<< HEAD
843 and a new feature
844 =======
845 and some more awesome changes
846 >>>>>>> zaney
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
847 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
848 \end{code}
9d50a72 @cbx33 Finished talking about merging
authored
849
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
850 We have displayed the contents of \texttt{newfile1} and \texttt{newfile2} during this merge.
851 At the moment, no commits have been made and we have a chance to tell Git exactly what these files should look like.
852 You should be able to see that Git has modified the files to show us what both the branches think the file should look like.
853 At the top, just after the \texttt{<<<<<<< HEAD} is how the line was modified in the \textbf{master} branch.
854 We then have a divider \texttt{=======} and after that we have the line, as it was modified in the \textbf{zaney} branch, followed by \texttt{>>>>>>> zaney}.
855 We can now edit these files manually, remove the dividers, header and footer and commit the result.
9d50a72 @cbx33 Finished talking about merging
authored
856
857 We are going to edit \texttt{newfile1} to look like this:
858
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
859 \begin{code}
9d50a72 @cbx33 Finished talking about merging
authored
860 A new file
861 and some more awesome changes
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
862 \end{code}
9d50a72 @cbx33 Finished talking about merging
authored
863
864 We will also edit \texttt{newfile2} to look like this:
865
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
866 \begin{code}
9d50a72 @cbx33 Finished talking about merging
authored
867 Another new file
868 and a new awesome feature
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
869 \end{code}
9d50a72 @cbx33 Finished talking about merging
authored
870
871 Now we have resolved the conflicts and set the files straight, we can add the files and commit the result.
872
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
873 \begin{code}
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
874 john@satsuki:~/coderepo$ git add newfile*
875 john@satsuki:~/coderepo$ git commit -a -m 'Merged in zaney'
876 [master d50ffb2] Merged in zaney
877 john@satsuki:~/coderepo$ git log -n2
878 commit d50ffb2fa536d869f2c4e89e8d6a48e0a29c5cc1
879 Merge: ed2301b 7cc32db
9d50a72 @cbx33 Finished talking about merging
authored
880 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
881 Date: Fri Apr 1 07:42:04 2011 +0100
9d50a72 @cbx33 Finished talking about merging
authored
882
883 Merged in zaney
884
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
885 commit ed2301ba223a63a5a930b536a043444e019460a7
9d50a72 @cbx33 Finished talking about merging
authored
886 Author: John Haskins <john.haskins@tamagoyakiinc.koala>
54bb969 @cbx33 Finished Chap4 (images left to do)
authored
887 Date: Fri Apr 1 07:37:34 2011 +0100
9d50a72 @cbx33 Finished talking about merging
authored
888
889 Removed third file
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
890 john@satsuki:~/coderepo$
ba9ffb2 Replace the Verbatim environment with custom listings environment
Johan Sageryd authored
891 \end{code}
2c6b38b @cbx33 Changed around some days
authored
892
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
893 Our merge has been completed.
894 Let us now see what our repository looks like graphically, in Figure 6.
be608d4 @cbx33 Added final image for chapter 4
authored
895
4321984 @cbx33 Removed figuregit for figuregith
authored
896 \figuregith{13cm}{images/f-w4-d6.pdf}{Repository state after \textbf{zaney} merge}
be608d4 @cbx33 Added final image for chapter 4
authored
897
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
898 It is quite reasonable that you may want to continue working on branches after you have integrate those changes back into your master.
899 Obviously you would have to merge your \textbf{master} branch back into \textbf{zaney} or any of the others, otherwise you could be developing on older versions of the code.
900 This brings up an interesting point which will be covered in a later chapter, as there are multiple ways to keep a development branch up to date.
51ba159 @cbx33 Added a little to chap4 to describe continuous integration
authored
901
ee21326 Remove trailing whitespace and wrap lines
Johan Sageryd authored
902 So, at the end of this week, we have learnt how to create branches, how to merge them, and how to resolve conflicts.
903 It should be stressed that a conflict is not a \textbf{bad} thing.
904 Conflicts do happen and when they do you should simply take your time and resolve the conflict in order to represent the \emph{best of both worlds}.
905 The \emph{After Hours} section for Week 4, takes a closer look at merging and explains some more about what branches are at a repository level.
8bfd6bb @cbx33 Modified the After Hours to have emph
authored
906
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
907 \clearpage
908 \section{Summary - John's Notes}
909 \subsection{Commands}
910 \begin{itemize}
061ca23 @cbx33 Fixed some underscore make issues
authored
911 \item\texttt{git branch <branch\_name>} - Creates a new branch with a given name
912 \item\texttt{git checkout <branch\_name>} - Switches to a new branch
07ad18a @cbx33 Added Jonas to ack
authored
913 \item\texttt{git log -n1} - Limits the output of the log command to only a single commit
a77cdf2 Fix speling
Johan Sageryd authored
914 \item\texttt{git branch -v} - Verbosely list all local branches
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
915 \item\texttt{git show <reference>} - Show the information pointed to by the reference
061ca23 @cbx33 Fixed some underscore make issues
authored
916 \item\texttt{git merge <branch\_name>} - Merge in a given branch to the current one
917 \item\texttt{git checkout -b <branch\_name>} - Create a new branch and switch into it in one go
7d99a60 @cbx33 Added John's notes about latest commands
authored
918 \item\texttt{git reset --hard <commit\_ref>} - Reset a branch to a specific commit reference
1518cba @cbx33 Updates to chapter 4
authored
919 \item\texttt{git log --graph --pretty=oneline --all \newline --abbrev-commit --decorate} - Shows a graphical view of the repository
3d7b48f @cbx33 More cleanup
authored
920 \item\texttt{git log --graph --oneline --all --decorate} - A shorter form of the above command
87f8677 @cbx33 Finished talking about deleting branches
authored
921 \item\texttt{git branch -d <branch\_name>} - Delete a branch that has already been merged
922 \item\texttt{git branch -D <branch\_name>} - Forcibly delete a branch
923 \item\texttt{git branch <branch\_name> <commit\_ref>} - Create a new branch, starting at the commit reference
e141b2b @cbx33 Added a few more to John's notes and finished chapter 4
authored
924 \item\texttt{git reset --merge} - Abort a merge and reset back to pre-merge state
1518cba @cbx33 Updates to chapter 4
authored
925 \item\texttt{git diff <commit\_1> <commit\_2> -- <files>} - Show the difference between the two commits, for certain files
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
926 \end{itemize}
682f68a @cbx33 Worked a lot more on chap4, ready for day 2
authored
927
85c6539 @cbx33 Added some more infomation on chap4 - branching
authored
928 \subsection{Terminology}
60053b3 @cbx33 General cleanup
authored
929 \begin{itemize}
1e87f43 @cbx33 Added Terminology
authored
930 \index{Terminology!Conflict}\item\textbf{Conflict} - A conflict occurs when an attempt is made to reconcile multiple changes to the same section of a file at the same time.
931 \index{Terminology!Fast-Forward Merge}\item\textbf{Fast-Forward Merge} - The simplest merge type, which simply winds a branch forward in time to meet the tip of another.
60053b3 @cbx33 General cleanup
authored
932 \end{itemize}
Something went wrong with that request. Please try again.