<
From version < 34.1 >
edited by msp
on 2012/10/16 13:25
To version < 49.2
edited by Richard Kreissig
on 2025/01/30 12:03
Change comment: Update document after refactoring.

Summary

Details

Page properties
Parent
... ... @@ -1,0 +1,1 @@
1 +Projects.Archive.Eclipse Practical (winter term 201213).Tutorials.WebHome
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.msp
1 +XWiki.stu230980
Content
... ... @@ -1,57 +1,59 @@
1 1  This tutorial will address the source code management (SCM) tool named [[Git>>url:http://git-scm.com/||shape="rect"]]. By following these steps you should learn about the basic usage of Git, which is required for the whole practical course. Furthermore, Git is a great SCM tool, and it's good to know how to use it. During this tutorial, we will follow Alan Turing's thoughts towards developing the [[Turing Machine>>url:http://en.wikipedia.org/wiki/Turing_machine||shape="rect"]].
2 2  
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.
3 +More in-depth Git 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. Furthermore, the shell command {{code language="none"}}git help{{/code}} lists the most commonly used Git commands, and {{code language="none"}}git help <command>{{/code}} gives very detailed documentation for the specified Git command.
4 4  
5 -==== Contents ====
5 +=== Contents ===
6 6  
7 7  
8 8  
9 -{{toc style="circle" maxLevel="3"/}}
9 +{{toc maxLevel="2" style="circle"/}}
10 10  
11 11  = Creating Commits =
12 12  
13 +Most steps of this tutorial are done by typing shell commands. The grey boxes contain the commands you should enter, preceded by a {{code language="none"}}${{/code}} symbol, and followed by their output. While you may copy & paste these commands, some of them may require modifications to adapt them to your own projects. The output will be slightly different for many commands when you enter them, since it also depends on parameters such as the user name and time of execution.
14 +
13 13  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).
14 -1. For Linux, Git is available in its own package. Windows users can install [[msysGit>>url:http://msysgit.github.com/||shape="rect"]]. For MacOS, Git is available as part of [[Xcode>>url:https://developer.apple.com/xcode/||shape="rect"]]; if you cannot install that, use [[Git for OSX>>url:http://code.google.com/p/git-osx-installer/||shape="rect"]].
16 +1. For Linux, Git is available in its own package. Windows users can install [[msysGit>>url:http://msysgit.github.com/||shape="rect"]]. For Mac OSX, Git is available as part of [[Xcode>>url:https://developer.apple.com/xcode/||shape="rect"]]; if you cannot install that, use [[Git for OSX>>url:http://code.google.com/p/git-osx-installer/||shape="rect"]].
15 15  1. (((
16 16  Configure your name and email address (will be included in all commits you create):
17 17  
18 -{{noformat}}
20 +{{code}}
19 19  $ git config --global --add user.name "Your Name"
20 20  $ git config --global --add user.email "<login>@informatik.uni-kiel.de"
21 -{{/noformat}}
23 +{{/code}}
22 22  )))
23 23  1. (((
24 24  Create a local repository for the "//Turing Project//":
25 25  
26 -{{noformat}}
28 +{{code}}
27 27  $ mkdir turing
28 28  $ cd turing
29 29  $ git init
30 30  Initialized empty Git repository in ~/turing/.git/
31 -{{/noformat}}
33 +{{/code}}
32 32  
33 -The {{code language="none"}}.git{{/code}} subdirectory contains all history and metadata of the repository. You should not modify it.
35 +The {{code language="none"}}.git{{/code}} subdirectory contains all history and metadata of the repository. You should not modify it. The {{code language="none"}}turing{{/code}} directory contains the //working copy//, that is the currently checked-out snapshot. You work by modifying your working copy and committing the modifications to the repository (contained in {{code language="none"}}.git{{/code}}).
34 34  )))
35 35  1. (((
36 36  Add and commit some content: copy [[attach:notes.txt]]{{code language="none"}}{{/code}} to your {{code language="none"}}turing{{/code}} directory.
37 37  
38 -{{noformat}}
40 +{{code}}
39 39  $ git add notes.txt
40 40  $ git commit -m "wrote some first notes"
41 41  [master (root-commit) 2e73b34] wrote some first notes
42 42   1 files changed, 5 insertions(+), 0 deletions(-)
43 43   create mode 100644 notes.txt
44 -{{/noformat}}
46 +{{/code}}
45 45  
46 46  The file is now stored in the local history of your repository.
47 47  )))
48 -1. Edit {{code language="none"}}notes.txt{{/code}}:\\
50 +1. Edit {{code language="none"}}notes.txt{{/code}}:
49 49  11. Replace "fixed" with "infinite" in line 1.
50 50  11. Replace "... (TODO)" with "a finite state machine" in line 4.
51 51  1. (((
52 52  View the status of your current working copy:
53 53  
54 -{{noformat}}
56 +{{code}}
55 55  $ git status
56 56  # On branch master
57 57  # Changed but not updated:
... ... @@ -61,12 +61,12 @@
61 61  # modified: notes.txt
62 62  #
63 63  no changes added to commit (use "git add" and/or "git commit -a")
64 -{{/noformat}}
66 +{{/code}}
65 65  )))
66 66  1. (((
67 67  Mark the modified file to include it in the next commit, then view the status again and compare with the previous output:
68 68  
69 -{{noformat}}
71 +{{code}}
70 70  $ git add notes.txt
71 71  $ git status
72 72  # On branch master
... ... @@ -75,12 +75,12 @@
75 75  #
76 76  # modified: notes.txt
77 77  #
78 -{{/noformat}}
80 +{{/code}}
79 79  )))
80 80  1. (((
81 81  Commit the modified content to your local repository and view the status:
82 82  
83 -{{noformat}}
85 +{{code}}
84 84  $ git commit -m "modified tape length, found a controller for tape head"
85 85  [master 52e2d49] modified tape length, found a controller for tape head
86 86   1 files changed, 2 insertions(+), 2 deletions(-)
... ... @@ -87,12 +87,12 @@
87 87  $ git status
88 88  # On branch master
89 89  nothing to commit (working directory clean)
90 -{{/noformat}}
92 +{{/code}}
91 91  )))
92 92  
93 93  After the preceding steps you have two commits in your local repository, each with one file in the index. You have different commands for viewing these commits:
94 94  
95 -{{noformat}}
97 +{{code}}
96 96  $ git log
97 97  commit 52e2d4946791c2725015853e5e261ce143c6fe8a
98 98  Author: Miro Spoenemann <msp@informatik.uni-kiel.de>
... ... @@ -124,29 +124,29 @@
124 124   * Tape head can move left or right
125 125  - * The head is controlled by ... (TODO)
126 126  + * The head is controlled by a finite state machine
127 -{{/noformat}}
129 +{{/code}}
128 128  
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"]]).
131 +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 Mac OSX is [[GitX>>url:http://gitx.frim.nl/||shape="rect"]]).
130 130  
131 131  = Branching and Merging =
132 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.
135 +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. In general, you may create as many local branches as you like, since they are simple to use and can be a great tool to structure your work.
134 134  
135 135  1. (((
136 136  Create a branch with name //sketches//:
137 137  
138 -{{noformat}}
140 +{{code}}
139 139  $ git branch sketches
140 -{{/noformat}}
142 +{{/code}}
141 141  )))
142 142  1. (((
143 143  View the list of branches:
144 144  
145 -{{noformat}}
147 +{{code}}
146 146  $ git branch
147 147  * master
148 148   sketches
149 -{{/noformat}}
151 +{{/code}}
150 150  
151 151  The star reveals that you are still on the old {{code language="none"}}master{{/code}} branch.
152 152  )))
... ... @@ -153,13 +153,13 @@
153 153  1. (((
154 154  Switch to the new branch:
155 155  
156 -{{noformat}}
158 +{{code}}
157 157  $ git checkout sketches
158 158  Switched to branch 'sketches'
159 159  $ git branch
160 160   master
161 161  * sketches
162 -{{/noformat}}
164 +{{/code}}
163 163  
164 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 165  )))
... ... @@ -166,13 +166,13 @@
166 166  1. (((
167 167  Download and add the new file [[attach:examples.txt]]{{code language="none"}}{{/code}}:
168 168  
169 -{{noformat}}
171 +{{code}}
170 170  $ git add examples.txt
171 171  $ git commit -m "wrote first examples"
172 172  [sketches cd63135] wrote first examples
173 173   1 files changed, 20 insertions(+), 0 deletions(-)
174 174   create mode 100644 examples.txt
175 -{{/noformat}}
177 +{{/code}}
176 176  
177 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 178  )))
... ... @@ -179,7 +179,7 @@
179 179  1. (((
180 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 181  
182 -{{noformat}}
184 +{{code}}
183 183  $ git checkout master
184 184  Switched to branch 'master'
185 185  $ git merge sketches
... ... @@ -188,7 +188,7 @@
188 188   examples.txt | 20 ++++++++++++++++++++
189 189   1 files changed, 20 insertions(+), 0 deletions(-)
190 190   create mode 100644 examples.txt
191 -{{/noformat}}
193 +{{/code}}
192 192  
193 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 194  )))
... ... @@ -195,74 +195,75 @@
195 195  1. (((
196 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 197  
198 -{{noformat}}
200 +{{code}}
199 199  $ git add notes.txt
200 200  $ git commit -m "added reference to the new examples"
201 201  [master a5e244f] added reference to the new examples
202 202   1 files changed, 2 insertions(+), 1 deletions(-)
203 -{{/noformat}}
205 +{{/code}}
204 204  )))
205 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.
208 +Switch back to the {{code language="none"}}sketches{{/code}} branch and modify it as shown below. 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 207  
208 -{{noformat}}
210 +{{code}}
209 209  $ git checkout sketches
210 210  Switched to branch 'sketches'
211 -{{/noformat}}
213 +{{/code}}
212 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.
215 +Add the line "{{code language="none"}}Move one step left:{{/code}}" followed by an accordingly updated version of the tape with tape head at the end of the file {{code language="none"}}examples.txt{{/code}}, then commit.
214 214  
215 -{{noformat}}
217 +{{code}}
216 216  $ git add examples.txt
217 217  $ git commit -m "added another example"
218 218  [sketches 55a9cb1] added another example
219 219   1 files changed, 5 insertions(+), 0 deletions(-)
220 -{{/noformat}}
222 +{{/code}}
221 221  
222 -Now our two branches have //diverged//, which means that they cannot be fast-forwarded anymore.
224 +Now your two branches have //diverged//, which means that they cannot be fast-forwarded anymore.
223 223  )))
224 224  1. (((
225 225  Merge the {{code language="none"}}master{{/code}} branch into {{code language="none"}}sketches{{/code}}:
226 226  
227 -{{noformat}}
229 +{{code}}
228 228  $ git merge master
229 229  Merge made by recursive.
230 230   notes.txt | 3 ++-
231 231   1 files changed, 2 insertions(+), 1 deletions(-)
232 -{{/noformat}}
234 +{{/code}}
233 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.
236 +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. See how both the change to {{code language="none"}}notes.txt{{/code}} done in the {{code language="none"}}master{{/code}} branch and the change to {{code language="none"}}examples.txt{{/code}} done in the {{code language="none"}}sketches{{/code}} branch are now contained in the repository state that results from the merge.
235 235  )))
236 236  1. (((
237 237  Add a commit in each of the two branches using the commands you have already learned.
240 +
238 238  1. Check out {{code language="none"}}master{{/code}}.
239 239  1. (((
240 240  Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}:
241 241  
242 -{{noformat nopanel="true"}}
245 +{{code nopanel="true"}}
243 243   * The finite state machine has an initial state and one or more final states
244 -{{/noformat}}
247 +{{/code}}
245 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).
249 +1. Commit the change o{{code language="none"}}notes.txt{{/code}}.
250 +1. Check out {{code language="none"}}sketches{{/code}} (make sure to refresh your text editor so that {{code language="none"}}notes.txt{{/code}} is reset to its previous state, without the change made above).
248 248  1. (((
249 249  Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}:
250 250  
251 -{{noformat nopanel="true"}}
254 +{{code nopanel="true"}}
252 252   * Each state transition can trigger head movement and data read/write
253 -{{/noformat}}
256 +{{/code}}
254 254  )))
255 -1. Commit the change to {{code language="none"}}notes.txt{{/code}}.
258 +1. Commit the change of {{code language="none"}}notes.txt{{/code}}.
256 256  )))
257 257  1. (((
258 258  Merge the {{code language="none"}}master{{/code}} branch into the current branch ({{code language="none"}}sketches{{/code}}):
259 259  
260 -{{noformat}}
263 +{{code}}
261 261  $ git merge master
262 262  Auto-merging notes.txt
263 263  CONFLICT (content): Merge conflict in notes.txt
264 264  Automatic merge failed; fix conflicts and then commit the result.
265 -{{/noformat}}
268 +{{/code}}
266 266  
267 267  As expected, the branches could not be merged automatically, since both branches modified the same line in the same file.
268 268  )))
... ... @@ -269,7 +269,7 @@
269 269  1. (((
270 270  Use the {{code language="none"}}status{{/code}} command to see the list of affected files:
271 271  
272 -{{noformat}}
275 +{{code}}
273 273  $ git status
274 274  # On branch sketches
275 275  # Unmerged paths:
... ... @@ -278,18 +278,18 @@
278 278  # both modified: notes.txt
279 279  #
280 280  no changes added to commit (use "git add" and/or "git commit -a")
281 -{{/noformat}}
284 +{{/code}}
282 282  )))
283 283  1. (((
284 284  The modified {{code language="none"}}notes.txt{{/code}} should now contain the following text:
285 285  
286 -{{noformat nopanel="true"}}
289 +{{code nopanel="true"}}
287 287  <<<<<<< HEAD
288 288   * Each state transition can trigger head movement and data read/write
289 289  =======
290 290   * The finite state machine has an initial state and one or more final states
291 291  >>>>>>> master
292 -{{/noformat}}
295 +{{/code}}
293 293  
294 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 295  )))
... ... @@ -296,7 +296,7 @@
296 296  1. (((
297 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 298  
299 -{{noformat}}
302 +{{code}}
300 300  $ git commit
301 301  [sketches 21d5ddb] Merge branch 'master' into sketches
302 302  $ git show 21d5ddb
... ... @@ -321,7 +321,7 @@
321 321   + * Each state transition can trigger head movement and data read/write
322 322  + * The finite state machine has an initial state and one or more final states
323 323   see some examples in 'examples.txt'
324 -{{/noformat}}
327 +{{/code}}
325 325  )))
326 326  
327 327  The {{code language="none"}}gitk{{/code}} tool should now display this graph:
... ... @@ -332,17 +332,21 @@
332 332  
333 333  In the previous sections you have worked only with a local repository. The next step is to share this content with a remote repository. Later we will use [[Stash>>url:https://www.atlassian.com/software/stash/overview||shape="rect"]] for repository management, but we need to create group accounts for you first, thus you will use another system called [[Gitorious>>url:https://git.rtsys.informatik.uni-kiel.de/||shape="rect"]] for now.
334 334  
338 +Usually it is sufficient to have only one local copy of a Git repository. However, in this tutorial you will create a second copy in order to "simulate" what can happen if two users access the same remote repository: imagine the directories {{code language="none"}}turing{{/code}} and {{code language="none"}}turing2{{/code}} are each managed by a different user. You will simulate the resulting interference by switching your working directory between these two.
339 +
335 335  1. Register to the Gitorious system: [[https:~~/~~/git.rtsys.informatik.uni-kiel.de/>>url:https://git.rtsys.informatik.uni-kiel.de/||shape="rect"]] (use your //Institut für Informatik// login name and email address)
336 336  1. Go to your //Dashboard// → //Manage SSH keys// → //Add SSH key//
337 -1. Copy & paste the content of your public SSH key.\\
342 +1. Copy & paste the content of your public SSH key.
338 338  1*. If you don't have an SSH key: use the shell command {{code language="none"}}ssh-keygen{{/code}}, confirm the default destination file {{code language="none"}}~/.ssh/id_rsa{{/code}}, and choose whether to give a passphrase. If you have a passphrase, you need to enter it whenever you use your SSH key for the first time in a session. You can omit the passphrase, but that makes the key less secure. As result, the tool generates a private key {{code language="none"}}~/.ssh/id_rsa{{/code}}, which has to be kept secret, and a public key {{code language="none"}}~/.ssh/id_rsa.pub{{/code}}.
339 339  1. Go to //Projects// → //Create a new project// and call it "personal-<login>", replacing <login> with your own login name.
340 340  1. On the next page, create a repository named "turing" (or select //Add repository// on your project page).
341 -1. Once you are on the repository page, copy the URL shown in //Clone & push urls//.
346 +1. On the repository page, go to //Manage collaborators// → //Add collaborators// and add the user msp.
347 +1. Once you are back on the repository page, copy the URL shown in //Clone & push urls//.
348 +1. Email the copied URL to [[msp@informatik.uni-kiel.de>>mailto:msp@informatik.uni-kiel.de||shape="rect"]]. This will serve as proof for your work on this tutorial.
342 342  1. (((
343 343  Transfer your {{code language="none"}}master{{/code}} branch to the new server-side repository. Replace the URL in the following command by the one copied from Gitorious:
344 344  
345 -{{noformat}}
352 +{{code}}
346 346  $ git remote add gitorious git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
347 347  $ git push gitorious master
348 348  Counting objects: 15, done.
... ... @@ -353,7 +353,7 @@
353 353  remote: => Syncing Gitorious... [OK]
354 354  To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
355 355   * [new branch] master -> master
356 -{{/noformat}}
363 +{{/code}}
357 357  
358 358  The first command adds a //remote// named "gitorious" to your local repository, which is just a bookmark for the long URL. The second command transfers the {{code language="none"}}master{{/code}} branch to the server, which is called //pushing//. After that is done, reload the Gitorious page in your browser, and you see all changes that are transferred to the server-side repository.
359 359  )))
... ... @@ -360,7 +360,7 @@
360 360  1. (((
361 361  Create a local clone of your remote repository (replace the URL accordingly):
362 362  
363 -{{noformat}}
370 +{{code}}
364 364  $ cd ..
365 365  $ git clone git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git turing2
366 366  Initialized empty Git repository in /home/msp/tmp/turing2/.git/
... ... @@ -370,15 +370,15 @@
370 370  Receiving objects: 100% (15/15), done.
371 371  Resolving deltas: 100% (3/3), done.
372 372  $ cd turing2
373 -{{/noformat}}
380 +{{/code}}
374 374  
375 -The {{code language="none"}}clone{{/code}} command automatically creates a remote named {{code language="none"}}origin{{/code}} in the new local repository, which is set to the given URL.
382 +The {{code language="none"}}clone{{/code}} command automatically creates a remote named {{code language="none"}}origin{{/code}} in the new local repository, which is set to the given URL. You will use this second clone to simulate another user with access to the repository.
376 376  )))
377 377  1. Edit the file {{code language="none"}}examples.txt{{/code}} in the new clone ({{code language="none"}}turing2{{/code}}): replace {{code language="none"}}"a"{{/code}} in line 6 by {{code language="none"}}"c"{{/code}} and correct the tape representations in lines 9, 14, and 19 accordingly. Commit the change.
378 378  1. (((
379 379  Push the new commit to the server:
380 380  
381 -{{noformat}}
388 +{{code}}
382 382  $ git push
383 383  Counting objects: 5, done.
384 384  Delta compression using up to 16 threads.
... ... @@ -388,11 +388,11 @@
388 388  remote: => Syncing Gitorious... [OK]
389 389  To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
390 390   8af2d50..1d1577f master -> master
391 -{{/noformat}}
398 +{{/code}}
392 392  
393 393  In this case the push command can be used without arguments, which means that it pushes all branches as configured in {{code language="none"}}.git/config{{/code}}:
394 394  
395 -{{noformat}}
402 +{{code}}
396 396  $ more .git/config
397 397  [core]
398 398   repositoryformatversion = 0
... ... @@ -405,7 +405,7 @@
405 405  [branch "master"]
406 406   remote = origin
407 407   merge = refs/heads/master
408 -{{/noformat}}
415 +{{/code}}
409 409  
410 410  Here the branch {{code language="none"}}master{{/code}} is linked with the remote {{code language="none"}}origin{{/code}}, hence {{code language="none"}}git push{{/code}} does the same as {{code language="none"}}git push origin master{{/code}}.
411 411  )))
... ... @@ -412,16 +412,16 @@
412 412  1. (((
413 413  Go back to the original local repository and check out the {{code language="none"}}master{{/code}} branch:
414 414  
415 -{{noformat}}
422 +{{code}}
416 416  $ cd ../turing
417 417  $ git checkout master
418 418  Switched to branch 'master'
419 -{{/noformat}}
426 +{{/code}}
420 420  )))
421 421  1. (((
422 422  Merge the {{code language="none"}}sketches{{/code}} branch into {{code language="none"}}master{{/code}}:
423 423  
424 -{{noformat}}
431 +{{code}}
425 425  $ git merge sketches
426 426  Updating 8af2d50..21d5ddb
427 427  Fast-forward
... ... @@ -428,7 +428,7 @@
428 428   examples.txt | 5 +++++
429 429   notes.txt | 1 +
430 430   2 files changed, 6 insertions(+), 0 deletions(-)
431 -{{/noformat}}
438 +{{/code}}
432 432  
433 433  Now your local {{code language="none"}}master{{/code}} branch and the one on the server-side repository have diverged
434 434  )))
... ... @@ -435,7 +435,7 @@
435 435  1. (((
436 436  Fetch the server-side changes:
437 437  
438 -{{noformat}}
445 +{{code}}
439 439  $ git fetch gitorious
440 440  remote: Counting objects: 5, done.
441 441  remote: Compressing objects: 100% (3/3), done.
... ... @@ -443,16 +443,16 @@
443 443  Unpacking objects: 100% (3/3), done.
444 444  From git.rtsys.informatik.uni-kiel.de:personal-msp/turing
445 445   8af2d50..1d1577f master -> gitorious/master
446 -{{/noformat}}
453 +{{/code}}
447 447  
448 448  Now the change to {{code language="none"}}examples.txt{{/code}} that was previously committed in the {{code language="none"}}turing2{{/code}} repository is stored in a //remote tracking branch// named {{code language="none"}}gitorious/master{{/code}}:
449 449  
450 -{{noformat}}
457 +{{code}}
451 451  $ git branch -a
452 452  * master
453 453   sketches
454 454   remotes/gitorious/master
455 -{{/noformat}}
462 +{{/code}}
456 456  
457 457  You can analyze the remote tracking branch using the {{code language="none"}}log{{/code}} and {{code language="none"}}show{{/code}} commands. However, you should never directly modify a remote tracking branch.
458 458  )))
... ... @@ -459,13 +459,13 @@
459 459  1. (((
460 460  You can merge the remote changes into your local {{code language="none"}}master{{/code}} branch with the following command:
461 461  
462 -{{noformat}}
469 +{{code}}
463 463  $ git merge gitorious/master
464 464  Auto-merging examples.txt
465 465  Merge made by recursive.
466 466   examples.txt | 8 ++++----
467 467   1 files changed, 4 insertions(+), 4 deletions(-)
468 -{{/noformat}}
475 +{{/code}}
469 469  
470 470  Since this combination of {{code language="none"}}fetch{{/code}} and {{code language="none"}}merge{{/code}} is used very often, Git offers a shortcut for it, namely the {{code language="none"}}pull{{/code}} command. In this case the according command would have been {{code language="none"}}git pull gitorious master{{/code}}.
471 471  )))
... ... @@ -472,7 +472,7 @@
472 472  1. (((
473 473  Push the merged branch to the server, and then push the {{code language="none"}}sketches{{/code}} branch, which is not on the server yet:
474 474  
475 -{{noformat}}
482 +{{code}}
476 476  $ git push gitorious master
477 477  Counting objects: 23, done.
478 478  Delta compression using up to 16 threads.
... ... @@ -487,19 +487,19 @@
487 487  remote: => Syncing Gitorious... [OK]
488 488  To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
489 489   * [new branch] sketches -> sketches
490 -{{/noformat}}
497 +{{/code}}
491 491  )))
492 492  1. (((
493 493  As next step change your working directory to the second local repository {{code language="none"}}turing2{{/code}}, add the following line to the end of {{code language="none"}}notes.txt{{/code}} in the {{code language="none"}}turing2{{/code}} directory, and commit the change:
494 494  
495 -{{noformat nopanel="true"}}
502 +{{code nopanel="true"}}
496 496  TODO: formal definition
497 -{{/noformat}}
504 +{{/code}}
498 498  )))
499 499  1. (((
500 500  Trying to push this commit to the server results in the following error message:
501 501  
502 -{{noformat}}
509 +{{code}}
503 503  $ git push
504 504  To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
505 505   ! [rejected] master -> master (non-fast-forward)
... ... @@ -507,7 +507,7 @@
507 507  To prevent you from losing history, non-fast-forward updates were rejected
508 508  Merge the remote changes before pushing again. See the 'Note about
509 509  fast-forwards' section of 'git push --help' for details.
510 -{{/noformat}}
517 +{{/code}}
511 511  
512 512  This is because you have modified the branch while working in the original {{code language="none"}}turing{{/code}} repository, and these changes have to be merged with the new commit you have just made for {{code language="none"}}notes.txt{{/code}}.
513 513  )))
... ... @@ -514,7 +514,7 @@
514 514  1. (((
515 515  The solution is to apply the {{code language="none"}}pull{{/code}} command followed by the {{code language="none"}}push{{/code}} command:
516 516  
517 -{{noformat}}
524 +{{code}}
518 518  $ git pull
519 519  remote: Counting objects: 23, done.
520 520  remote: Compressing objects: 100% (14/14), done.
... ... @@ -537,20 +537,20 @@
537 537  remote: => Syncing Gitorious... [OK]
538 538  To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
539 539   957f686..b58ded7 master -> master
540 -{{/noformat}}
547 +{{/code}}
541 541  
542 -While {{code language="none"}}pull{{/code}} performs a {{code language="none"}}fetch{{/code}} and a {{code language="none"}}merge{{/code}}, {{code language="none"}}push{{/code}} transfers the new merged branch to the server. Note that during the merge operation conflicts can occur. In that case you have to resolve them and commit the changes before you can push.
549 +While {{code language="none"}}pull{{/code}} performs a {{code language="none"}}fetch{{/code}} and a {{code language="none"}}merge{{/code}}, {{code language="none"}}push{{/code}} transfers the new merged branch to the server. Note that during the merge operation conflicts can occur. In that case you have to resolve them and commit the changes before you can push. When used without parameters like shown above, {{code language="none"}}pull{{/code}} lookes in {{code language="none"}}.git/config{{/code}} to determine which branches to pull from which remotes.
543 543  )))
544 544  1. (((
545 -In order to check out the {{code language="none"}}sketches{{/code}} branch, which was previously pushed to the server, simply type the following command:
552 +In order to check out the {{code language="none"}}sketches{{/code}} branch locally, which was previously pushed to the server, simply type the following command:
546 546  
547 -{{noformat}}
554 +{{code}}
548 548  $ git checkout sketches
549 549  Branch sketches set up to track remote branch sketches from origin.
550 550  Switched to a new branch 'sketches'
551 -{{/noformat}}
558 +{{/code}}
552 552  
553 -This branch can be pushed and pulled with the server in the same way as you did for the {{code language="none"}}master{{/code}} branch.
560 +This branch can be pushed and pulled with the server in the same way as you did for the {{code language="none"}}master{{/code}} branch. Never check out {{code language="none"}}origin/sketches{{/code}}, since that is a remote tracking branch!
554 554  )))
555 555  
556 556  The {{code language="none"}}master{{/code}} branch should look like this:
... ... @@ -557,4 +557,146 @@
557 557  
558 558  [[image:attach:turing-graph-02.png]]
559 559  
560 -
567 += Other Useful Commands =
568 +
569 +This section contains optional steps that you don't need to push online, but can be useful for you to learn.
570 +
571 +=== Ignoring Files ===
572 +
573 +While working on his Machine, Alan Turing has produced a temporary file {{code language="none"}}experiments.tmp{{/code}}, which he does not want to commit in the repository:
574 +
575 +{{code}}
576 +$ git status
577 +# On branch master
578 +# Untracked files:
579 +# (use "git add <file>..." to include in what will be committed)
580 +#
581 +# experiments.tmp
582 +nothing added to commit but untracked files present (use "git add" to track)
583 +{{/code}}
584 +
585 +Since the extra mention of that file can make Git's status reports unnecessarily cluttered, Alan wants to ignore it permanently. Help him by adding a {{code language="none"}}.gitignore{{/code}} file to the repository:
586 +
587 +{{code}}
588 +$ echo "*.tmp" > .gitignore
589 +$ git add .gitignore
590 +$ git commit -m "added ignore file"
591 +[master 738ce4c] added ignore file
592 + 1 files changed, 1 insertions(+), 0 deletions(-)
593 + create mode 100644 .gitignore
594 +$ git status
595 +# On branch master
596 +# Your branch is ahead of 'origin/master' by 1 commit.
597 +#
598 +nothing to commit (working directory clean)
599 +{{/code}}
600 +
601 +Now the experiments.tmp{{code language="none"}}{{/code}} file is not considered when viewing the status. You can add arbitrary file name patterns to the {{code language="none"}}.gitignore{{/code}} file; for example it is a good idea to ignore {{code language="none"}}*.class{{/code}}, which are binary files generated for Java projects.
602 +
603 +=== Discarding Changes ===
604 +
605 +While working on his Machine, Alan Turing has made some changes to notes.txt that he later found out to be nonsense:
606 +
607 +{{code}}
608 +$ git status
609 +# On branch master
610 +# Changed but not updated:
611 +# (use "git add <file>..." to update what will be committed)
612 +# (use "git checkout -- <file>..." to discard changes in working directory)
613 +#
614 +# modified: notes.txt
615 +#
616 +no changes added to commit (use "git add" and/or "git commit -a")
617 +{{/code}}
618 +
619 +Help Alan by restoring the last committed state of that file:
620 +
621 +{{code}}
622 +$ git checkout HEAD notes.txt
623 +$ git status
624 +# On branch master
625 +nothing to commit (working directory clean)
626 +{{/code}}
627 +
628 +Instead of HEAD, which is the last commit on the current branch, you can also name any other branch or commit hash. In that case you would have to commit the change to make it permanent. While resolving conflicts it is possible to use {{code language="none"}}--theirs{{/code}} or {{code language="none"}}--ours{{/code}} instead of HEAD, which replaces the whole content of the respective file by their version (the one on the remote branch) or our version (the one on the current branch).
629 +
630 +A more brute-force option is using the {{code language="none"}}reset{{/code}} command:
631 +
632 +{{code}}
633 +$ git reset --hard
634 +HEAD is now at b58ded7 Merge branch 'master' of git.rtsys.informatik.uni-kiel.de:personal-msp/turing
635 +{{/code}}
636 +
637 +This resets //all// changes to the working copy to the head of the current branch, so use it with caution! However, {{code language="none"}}reset{{/code}} does not remove unstaged files. In order to do that in one command, use {{code language="none"}}clean{{/code}}:
638 +
639 +{{code}}
640 +$ git status
641 +# On branch master
642 +# Untracked files:
643 +# (use "git add <file>..." to include in what will be committed)
644 +#
645 +# test1.tmp
646 +# test2.tmp
647 +nothing added to commit but untracked files present (use "git add" to track)
648 +$ git clean -f
649 +Removing test1.tmp
650 +Removing test2.tmp
651 +{{/code}}
652 +
653 +=== Rebasing ===
654 +
655 +Consider the following situation:
656 +
657 +[[image:attach:turing-graph-03.png]]
658 +
659 +If you want to merge the changes made on the {{code language="none"}}master{{/code}} branch into the {{code language="none"}}sketches{{/code}} branch, the normal way is to use the {{code language="none"}}merge{{/code}} command and create a merge commit. However, the {{code language="none"}}rebase{{/code}} command gives an interesting alternative to that: it reapplies all commits done in the current branch starting from a given reference.
660 +
661 +{{code}}
662 +$ git rebase master
663 +First, rewinding head to replay your work on top of it...
664 +Applying: added another example
665 +Applying: state transitions
666 +Using index info to reconstruct a base tree...
667 +Falling back to patching base and 3-way merge...
668 +Auto-merging notes.txt
669 +{{/code}}
670 +
671 +Afterwards the commit graph looks like this:
672 +
673 +[[image:attach:turing-graph-04.png]]
674 +
675 +The two commits made in {{code language="none"}}sketches{{/code}} are reapplied starting from the head of the {{code language="none"}}master{{/code}} branch. The resulting structure of commits is much cleaner than before. rebase{{code language="none"}}{{/code}} even allows to squeeze multiple commits into one. Note that in this example a merge conflict had to be resolved in the same way as it was done in Section "Branching and Merging"; instead of committing the resolved file, the rebase command is resumed with {{code language="none"}}git rebase --continue{{/code}}.
676 +
677 +{{warning}}
678 +Never rebase a branch that is already pushed online! Due to the structural change the rebased branch is no longer compatible with the previous one, and pushing it will fail, since fast-forward merge is not possible.
679 +{{/warning}}
680 +
681 +=== Tagging ===
682 +
683 +Finally Alan Turing has made a great success in the development of his Machine, and he would like to fix that stage as "Milestone 1". Help him by tagging the current state of the project:
684 +
685 +{{code}}
686 +$ git tag milestone1
687 +{{/code}}
688 +
689 +Then the head of the current branch is stored under the name {{code language="none"}}milestone1{{/code}}, so it can be found very easily at later stages of the project:
690 +
691 +{{code}}
692 +$ git tag
693 +milestone1
694 +$ git checkout milestone1
695 +Note: checking out 'milestone1'.
696 +
697 +You are in 'detached HEAD' state. You can look around, make experimental
698 +changes and commit them, and you can discard any commits you make in this
699 +state without impacting any branches by performing another checkout.
700 +
701 +If you want to create a new branch to retain commits you create, you may
702 +do so (now or later) by using -b with the checkout command again. Example:
703 +
704 + git checkout -b new_branch_name
705 +
706 +HEAD is now at 957f686... Merge remote branch 'gitorious/master'
707 +{{/code}}
708 +
709 +Tags can also be loaded to the server using the {{code language="none"}}push{{/code}} command.
examples.txt
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +192 bytes
Content
... ... @@ -1,0 +1,21 @@
1 +Empty tape with tape head:
2 +
3 + V
4 +----------------
5 +
6 +Write character "a":
7 +
8 + V
9 +----a-----------
10 +
11 +Move one step right:
12 +
13 + V
14 +----a-----------
15 +
16 +Write character "b":
17 +
18 + V
19 +----ab----------
20 +
21 +
notes.txt
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +142 bytes
Content
... ... @@ -1,0 +1,6 @@
1 + * A tape with fixed length
2 + * Tape head can read or write data
3 + * Tape head can move left or right
4 + * The head is controlled by ... (TODO)
5 +
6 +
turing-graph-01.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +2.9 KB
Content
turing-graph-02.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +5.4 KB
Content
turing-graph-03.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +2.5 KB
Content
turing-graph-04.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +2.1 KB
Content
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -2982151
1 +2982081
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982151/Git
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982081/Git