<
From version < 30.1 >
edited by msp
on 2012/10/16 10:56
To version < 28.1 >
edited by msp
on 2012/10/15 15:18
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -23,8 +23,6 @@
23 23  $ git init
24 24  Initialized empty Git repository in ~/turing/.git/
25 25  {{/noformat}}
26 -
27 -The {{code language="none"}}.git{{/code}} subdirectory contains all history and metadata of the repository. You should not modify it.
28 28  )))
29 29  1. (((
30 30  Add and commit some content: copy [[attach:notes.txt]]{{code language="none"}}{{/code}} to your {{code language="none"}}turing{{/code}} directory.
... ... @@ -36,8 +36,6 @@
36 36   1 files changed, 5 insertions(+), 0 deletions(-)
37 37   create mode 100644 notes.txt
38 38  {{/noformat}}
39 -
40 -The file is now stored in the local history of your repository.
41 41  )))
42 42  1. Edit {{code language="none"}}notes.txt{{/code}}:\\
43 43  11. Replace "fixed" with "infinite" in line 1.
... ... @@ -120,206 +120,4 @@
120 120  + * The head is controlled by a finite state machine
121 121  {{/noformat}}
122 122  
123 -Note that each commit is identified by a looong hash value, but it is possible to use only a prefix when referencing them (if the prefix is not ambiguous): the example above uses {{code language="none"}}52e2d49{{/code}} to identify the second commit. The commit hashes in your repository will be different from those seen in this tutorial, because the name of the author and the exact time of committing is also considered in the hash calculation. Also try the command {{code language="none"}}gitk{{/code}} to get an overview of your commits (a better alternative available for MacOS is [[GitX>>url:http://gitx.frim.nl/||shape="rect"]]).
124 -
125 -= Branching and Merging =
126 -
127 -In the previous section you have created two commits on the default branch, which is named {{code language="none"}}master{{/code}}. Now you will create a new branch and commit there, thus adding complexity to the commit graph.
128 -
129 -1. (((
130 -Create a branch with name //sketches//:
131 -
132 -{{noformat}}
133 -$ git branch sketches
134 -{{/noformat}}
135 -)))
136 -1. (((
137 -View the list of branches:
138 -
139 -{{noformat}}
140 -$ git branch
141 -* master
142 - sketches
143 -{{/noformat}}
144 -
145 -The star reveals that you are still on the old {{code language="none"}}master{{/code}} branch.
146 -)))
147 -1. (((
148 -Switch to the new branch:
149 -
150 -{{noformat}}
151 -$ git checkout sketches
152 -Switched to branch 'sketches'
153 -$ git branch
154 - master
155 -* sketches
156 -{{/noformat}}
157 -
158 -It is also possible to create a branch and switch immediately to it using the option {{code language="none"}}-b{{/code}} of {{code language="none"}}git checkout{{/code}}.
159 -)))
160 -1. (((
161 -Download and add the new file [[attach:examples.txt]]{{code language="none"}}{{/code}}:
162 -
163 -{{noformat}}
164 -$ git add examples.txt
165 -$ git commit -m "wrote first examples"
166 -[sketches cd63135] wrote first examples
167 - 1 files changed, 20 insertions(+), 0 deletions(-)
168 - create mode 100644 examples.txt
169 -{{/noformat}}
170 -
171 -Inspecting the commit graph with {{code language="none"}}gitk{{/code}} (or another graphical viewer) you see that the {{code language="none"}}sketches{{/code}} branch now has three commits, while {{code language="none"}}master{{/code}} is still at the second commit.
172 -)))
173 -1. (((
174 -Merging the {{code language="none"}}sketches{{/code}} branch into {{code language="none"}}master{{/code}} means that all changes that have been made in {{code language="none"}}sketches{{/code}} are also applied to {{code language="none"}}master{{/code}}. In order to perform this merge, we have to check out the {{code language="none"}}master{{/code}} branch first:
175 -
176 -{{noformat}}
177 -$ git checkout master
178 -Switched to branch 'master'
179 -$ git merge sketches
180 -Updating 52e2d49..cd63135
181 -Fast-forward
182 - examples.txt | 20 ++++++++++++++++++++
183 - 1 files changed, 20 insertions(+), 0 deletions(-)
184 - create mode 100644 examples.txt
185 -{{/noformat}}
186 -
187 -This was a //fast-forward// merge: since the {{code language="none"}}master{{/code}} branch was completely contained in the {{code language="none"}}sketches{{/code}} branch, the merge could be done by simply changing the head pointer of {{code language="none"}}master{{/code}} to be the same as the head of {{code language="none"}}sketches{{/code}}.
188 -)))
189 -1. (((
190 -Now add the line "{{code language="none"}}see some examples in 'examples.txt'{{/code}}" to the file {{code language="none"}}notes.txt{{/code}} and commit this change in the current branch:
191 -
192 -{{noformat}}
193 -$ git add notes.txt
194 -$ git commit -m "added reference to the new examples"
195 -[master a5e244f] added reference to the new examples
196 - 1 files changed, 2 insertions(+), 1 deletions(-)
197 -{{/noformat}}
198 -)))
199 -1. (((
200 -Switch back to the {{code language="none"}}sketches{{/code}} branch and commit something there. Note that the {{code language="none"}}checkout{{/code}} command modifies your working copy, hence you have to update your text editor's content if you opened one of the files.
201 -
202 -{{noformat}}
203 -$ git checkout sketches
204 -Switched to branch 'sketches'
205 -{{/noformat}}
206 -
207 -Add the line "{{code language="none"}}Move one step left:{{/code}}" and write an updated version of the tape with tape head in the file {{code language="none"}}examples.txt{{/code}}, then commit.
208 -
209 -{{noformat}}
210 -$ git add examples.txt
211 -$ git commit -m "added another example"
212 -[sketches 55a9cb1] added another example
213 - 1 files changed, 5 insertions(+), 0 deletions(-)
214 -{{/noformat}}
215 -
216 -Now our two branches have //diverged//, which means that they cannot be fast-forwarded anymore.
217 -)))
218 -1. (((
219 -Merge the {{code language="none"}}master{{/code}} branch into {{code language="none"}}sketches{{/code}}:
220 -
221 -{{noformat}}
222 -$ git merge master
223 -Merge made by recursive.
224 - notes.txt | 3 ++-
225 - 1 files changed, 2 insertions(+), 1 deletions(-)
226 -{{/noformat}}
227 -
228 -Using {{code language="none"}}gitk{{/code}} you can see that a new commit was created that has two parent commits. Such a commit is called //merge// commit and is done automatically when a non-fast-forward merge is applied.
229 -)))
230 -1. (((
231 -Add a commit in each of the two branches using the commands you have already learned.
232 -1. Check out {{code language="none"}}master{{/code}}.
233 -1. (((
234 -Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}:
235 -
236 -{{noformat nopanel="true"}}
237 - * The finite state machine has an initial state and one or more final states
238 -{{/noformat}}
239 -)))
240 -1. Commit the change to {{code language="none"}}notes.txt{{/code}}.
241 -1. Check out {{code language="none"}}sketches{{/code}} (make sure to refresh your text editor so {{code language="none"}}notes.txt{{/code}} is reset to its previous state, without the change made above).
242 -1. (((
243 -Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}:
244 -
245 -{{noformat nopanel="true"}}
246 - * Each state transition can trigger head movement and data read/write
247 -{{/noformat}}
248 -)))
249 -1. Commit the change to {{code language="none"}}notes.txt{{/code}}.
250 -)))
251 -1. (((
252 -Merge the {{code language="none"}}master{{/code}} branch into the current branch ({{code language="none"}}sketches{{/code}}):
253 -
254 -{{noformat}}
255 -$ git merge master
256 -Auto-merging notes.txt
257 -CONFLICT (content): Merge conflict in notes.txt
258 -Automatic merge failed; fix conflicts and then commit the result.
259 -{{/noformat}}
260 -
261 -As expected, the branches could not be merged automatically, since both branches modified the same line in the same file.
262 -)))
263 -1. (((
264 -Use the {{code language="none"}}status{{/code}} command to see the list of affected files:
265 -
266 -{{noformat}}
267 -$ git status
268 -# On branch sketches
269 -# Unmerged paths:
270 -# (use "git add/rm <file>..." as appropriate to mark resolution)
271 -#
272 -# both modified: notes.txt
273 -#
274 -no changes added to commit (use "git add" and/or "git commit -a")
275 -{{/noformat}}
276 -)))
277 -1. (((
278 -The modified {{code language="none"}}notes.txt{{/code}} should now contain the following text:
279 -
280 -{{noformat nopanel="true"}}
281 -<<<<<<< HEAD
282 - * Each state transition can trigger head movement and data read/write
283 -=======
284 - * The finite state machine has an initial state and one or more final states
285 ->>>>>>> master
286 -{{/noformat}}
287 -
288 -The upper line is the one committed to {{code language="none"}}sketches{{/code}}, while the lower line was committed to {{code language="none"}}master{{/code}}. You have to resolve the conflict by editing the file. In this case the conflict is resolved by keeping both lines in arbitrary order, that means you should just remove the conflict markers (lines 5, 7, and 9 in {{code language="none"}}notes.txt{{/code}}).
289 -)))
290 -1. (((
291 -Use the {{code language="none"}}add{{/code}} command to mark {{code language="none"}}notes.txt{{/code}} as resolved. Entering {{code language="none"}}git commit{{/code}} without a message will open a text editor with an automatically created commit message. Just close the editor, and the merge commit is completed:
292 -
293 -{{noformat}}
294 -$ git commit
295 -[sketches 21d5ddb] Merge branch 'master' into sketches
296 -$ git show 21d5ddb
297 -commit 21d5ddbbcba4e36464653a2a550dbf595ead921f
298 -Merge: 17f75c7 8af2d50
299 -Author: Miro Spoenemann <msp@informatik.uni-kiel.de>
300 -Date: Tue Oct 16 10:44:09 2012 +0200
301 -
302 - Merge branch 'master' into sketches
303 -
304 - Conflicts:
305 - notes.txt
306 -
307 -diff --cc notes.txt
308 -index 8f72873,bb81298..ba94a08
309 ---- a/notes.txt
310 -+++ b/notes.txt
311 -@@@ -2,6 -2,6 +2,7 @@@
312 - * Tape head can read or write data
313 - * Tape head can move left or right
314 - * The head is controlled by a finite state machine
315 - + * Each state transition can trigger head movement and data read/write
316 -+ * The finite state machine has an initial state and one or more final states
317 - see some examples in 'examples.txt'
318 -{{/noformat}}
319 -)))
320 -
321 -The {{code language="none"}}gitk{{/code}} tool should now display this graph:
322 -
323 -[[image:attach:turing-graph-01.png]]
324 -
325 -
119 +Note that each commit is identified by a looong hash value, but it is possible to use only a prefix when referencing them (if the prefix is not ambiguous): the example above uses {{code language="none"}}52e2d49{{/code}} to identify the second commit. Also try the command {{code language="none"}}gitk{{/code}} to get an overview of your commits (a better alternative available for MacOS is [[GitX>>url:http://gitx.frim.nl/||shape="rect"]]). The commit hashes in your repository will be different from those seen in this tutorial, because the name of the author and the exact time of committing is also considered in the hash calculation.
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -2982134
1 +2982126
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982134/Git
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982126/Git