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

Summary

Details

Page properties
Content
... ... @@ -2,6 +2,12 @@
2 2  
3 3  More in-depth documentation can be found on the [[official home page>>url:http://git-scm.com/documentation||shape="rect"]], which mentions books, videos, and links to other tutorials and references.
4 4  
5 +==== Contents ====
6 +
7 +
8 +
9 +{{toc style="circle" maxLevel="3"/}}
10 +
5 5  = Creating Commits =
6 6  
7 7  1. Read the [[Git for Computer Scientists>>url:http://eagain.net/articles/git-for-computer-scientists/||shape="rect"]] introduction (skip this if you are already familiar with Git).
... ... @@ -23,6 +23,8 @@
23 23  $ git init
24 24  Initialized empty Git repository in ~/turing/.git/
25 25  {{/noformat}}
32 +
33 +The {{code language="none"}}.git{{/code}} subdirectory contains all history and metadata of the repository. You should not modify it.
26 26  )))
27 27  1. (((
28 28  Add and commit some content: copy [[attach:notes.txt]]{{code language="none"}}{{/code}} to your {{code language="none"}}turing{{/code}} directory.
... ... @@ -34,6 +34,8 @@
34 34   1 files changed, 5 insertions(+), 0 deletions(-)
35 35   create mode 100644 notes.txt
36 36  {{/noformat}}
45 +
46 +The file is now stored in the local history of your repository.
37 37  )))
38 38  1. Edit {{code language="none"}}notes.txt{{/code}}:\\
39 39  11. Replace "fixed" with "infinite" in line 1.
... ... @@ -116,4 +116,206 @@
116 116  + * The head is controlled by a finite state machine
117 117  {{/noformat}}
118 118  
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.
129 +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"]]).
130 +
131 += Branching and Merging =
132 +
133 +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.
134 +
135 +1. (((
136 +Create a branch with name //sketches//:
137 +
138 +{{noformat}}
139 +$ git branch sketches
140 +{{/noformat}}
141 +)))
142 +1. (((
143 +View the list of branches:
144 +
145 +{{noformat}}
146 +$ git branch
147 +* master
148 + sketches
149 +{{/noformat}}
150 +
151 +The star reveals that you are still on the old {{code language="none"}}master{{/code}} branch.
152 +)))
153 +1. (((
154 +Switch to the new branch:
155 +
156 +{{noformat}}
157 +$ git checkout sketches
158 +Switched to branch 'sketches'
159 +$ git branch
160 + master
161 +* sketches
162 +{{/noformat}}
163 +
164 +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}}.
165 +)))
166 +1. (((
167 +Download and add the new file [[attach:examples.txt]]{{code language="none"}}{{/code}}:
168 +
169 +{{noformat}}
170 +$ git add examples.txt
171 +$ git commit -m "wrote first examples"
172 +[sketches cd63135] wrote first examples
173 + 1 files changed, 20 insertions(+), 0 deletions(-)
174 + create mode 100644 examples.txt
175 +{{/noformat}}
176 +
177 +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.
178 +)))
179 +1. (((
180 +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:
181 +
182 +{{noformat}}
183 +$ git checkout master
184 +Switched to branch 'master'
185 +$ git merge sketches
186 +Updating 52e2d49..cd63135
187 +Fast-forward
188 + examples.txt | 20 ++++++++++++++++++++
189 + 1 files changed, 20 insertions(+), 0 deletions(-)
190 + create mode 100644 examples.txt
191 +{{/noformat}}
192 +
193 +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}}.
194 +)))
195 +1. (((
196 +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:
197 +
198 +{{noformat}}
199 +$ git add notes.txt
200 +$ git commit -m "added reference to the new examples"
201 +[master a5e244f] added reference to the new examples
202 + 1 files changed, 2 insertions(+), 1 deletions(-)
203 +{{/noformat}}
204 +)))
205 +1. (((
206 +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.
207 +
208 +{{noformat}}
209 +$ git checkout sketches
210 +Switched to branch 'sketches'
211 +{{/noformat}}
212 +
213 +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.
214 +
215 +{{noformat}}
216 +$ git add examples.txt
217 +$ git commit -m "added another example"
218 +[sketches 55a9cb1] added another example
219 + 1 files changed, 5 insertions(+), 0 deletions(-)
220 +{{/noformat}}
221 +
222 +Now our two branches have //diverged//, which means that they cannot be fast-forwarded anymore.
223 +)))
224 +1. (((
225 +Merge the {{code language="none"}}master{{/code}} branch into {{code language="none"}}sketches{{/code}}:
226 +
227 +{{noformat}}
228 +$ git merge master
229 +Merge made by recursive.
230 + notes.txt | 3 ++-
231 + 1 files changed, 2 insertions(+), 1 deletions(-)
232 +{{/noformat}}
233 +
234 +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.
235 +)))
236 +1. (((
237 +Add a commit in each of the two branches using the commands you have already learned.
238 +1. Check out {{code language="none"}}master{{/code}}.
239 +1. (((
240 +Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}:
241 +
242 +{{noformat nopanel="true"}}
243 + * The finite state machine has an initial state and one or more final states
244 +{{/noformat}}
245 +)))
246 +1. Commit the change to {{code language="none"}}notes.txt{{/code}}.
247 +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).
248 +1. (((
249 +Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}:
250 +
251 +{{noformat nopanel="true"}}
252 + * Each state transition can trigger head movement and data read/write
253 +{{/noformat}}
254 +)))
255 +1. Commit the change to {{code language="none"}}notes.txt{{/code}}.
256 +)))
257 +1. (((
258 +Merge the {{code language="none"}}master{{/code}} branch into the current branch ({{code language="none"}}sketches{{/code}}):
259 +
260 +{{noformat}}
261 +$ git merge master
262 +Auto-merging notes.txt
263 +CONFLICT (content): Merge conflict in notes.txt
264 +Automatic merge failed; fix conflicts and then commit the result.
265 +{{/noformat}}
266 +
267 +As expected, the branches could not be merged automatically, since both branches modified the same line in the same file.
268 +)))
269 +1. (((
270 +Use the {{code language="none"}}status{{/code}} command to see the list of affected files:
271 +
272 +{{noformat}}
273 +$ git status
274 +# On branch sketches
275 +# Unmerged paths:
276 +# (use "git add/rm <file>..." as appropriate to mark resolution)
277 +#
278 +# both modified: notes.txt
279 +#
280 +no changes added to commit (use "git add" and/or "git commit -a")
281 +{{/noformat}}
282 +)))
283 +1. (((
284 +The modified {{code language="none"}}notes.txt{{/code}} should now contain the following text:
285 +
286 +{{noformat nopanel="true"}}
287 +<<<<<<< HEAD
288 + * Each state transition can trigger head movement and data read/write
289 +=======
290 + * The finite state machine has an initial state and one or more final states
291 +>>>>>>> master
292 +{{/noformat}}
293 +
294 +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}}).
295 +)))
296 +1. (((
297 +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:
298 +
299 +{{noformat}}
300 +$ git commit
301 +[sketches 21d5ddb] Merge branch 'master' into sketches
302 +$ git show 21d5ddb
303 +commit 21d5ddbbcba4e36464653a2a550dbf595ead921f
304 +Merge: 17f75c7 8af2d50
305 +Author: Miro Spoenemann <msp@informatik.uni-kiel.de>
306 +Date: Tue Oct 16 10:44:09 2012 +0200
307 +
308 + Merge branch 'master' into sketches
309 +
310 + Conflicts:
311 + notes.txt
312 +
313 +diff --cc notes.txt
314 +index 8f72873,bb81298..ba94a08
315 +--- a/notes.txt
316 ++++ b/notes.txt
317 +@@@ -2,6 -2,6 +2,7 @@@
318 + * Tape head can read or write data
319 + * Tape head can move left or right
320 + * The head is controlled by a finite state machine
321 + + * Each state transition can trigger head movement and data read/write
322 ++ * The finite state machine has an initial state and one or more final states
323 + see some examples in 'examples.txt'
324 +{{/noformat}}
325 +)))
326 +
327 +The {{code language="none"}}gitk{{/code}} tool should now display this graph:
328 +
329 +[[image:attach:turing-graph-01.png]]
330 +
331 +
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -2982126
1 +2982137
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982126/Git
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982137/Git