<
From version < 37.1 >
edited by msp
on 2012/10/16 14:44
To version < 33.1 >
edited by msp
on 2012/10/16 11:37
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,6 +1,6 @@
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 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.
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 5  ==== Contents ====
6 6  
... ... @@ -10,10 +10,8 @@
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, together with their output. While you may copy & paste these commands, some of them may require modifications to adapt them to your own projects.
14 -
15 15  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).
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"]].
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"]].
17 17  1. (((
18 18  Configure your name and email address (will be included in all commits you create):
19 19  
... ... @@ -32,7 +32,7 @@
32 32  Initialized empty Git repository in ~/turing/.git/
33 33  {{/noformat}}
34 34  
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}}).
33 +The {{code language="none"}}.git{{/code}} subdirectory contains all history and metadata of the repository. You should not modify it.
36 36  )))
37 37  1. (((
38 38  Add and commit some content: copy [[attach:notes.txt]]{{code language="none"}}{{/code}} to your {{code language="none"}}turing{{/code}} directory.
... ... @@ -128,7 +128,7 @@
128 128  + * The head is controlled by a finite state machine
129 129  {{/noformat}}
130 130  
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"]]).
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"]]).
132 132  
133 133  = Branching and Merging =
134 134  
... ... @@ -338,226 +338,6 @@
338 338  1. Go to your //Dashboard// → //Manage SSH keys// → //Add SSH key//
339 339  1. Copy & paste the content of your public SSH key.\\
340 340  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}}.
341 -1. Go to //Projects// → //Create a new project// and call it "personal-<login>", replacing <login> with your own login name.
339 +1. Go to //Projects// → //Create a new project// and call it "<login>-private", replacing <login> with your own login name.
342 342  1. On the next page, create a repository named "turing" (or select //Add repository// on your project page).
343 343  1. Once you are on the repository page, copy the URL shown in //Clone & push urls//.
344 -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.
345 -1. (((
346 -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:
347 -
348 -{{noformat}}
349 -$ git remote add gitorious git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
350 -$ git push gitorious master
351 -Counting objects: 15, done.
352 -Delta compression using up to 16 threads.
353 -Compressing objects: 100% (13/13), done.
354 -Writing objects: 100% (15/15), 1.54 KiB, done.
355 -Total 15 (delta 3), reused 0 (delta 0)
356 -remote: => Syncing Gitorious... [OK]
357 -To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
358 - * [new branch] master -> master
359 -{{/noformat}}
360 -
361 -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.
362 -)))
363 -1. (((
364 -Create a local clone of your remote repository (replace the URL accordingly):
365 -
366 -{{noformat}}
367 -$ cd ..
368 -$ git clone git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git turing2
369 -Initialized empty Git repository in /home/msp/tmp/turing2/.git/
370 -remote: Counting objects: 15, done.
371 -remote: Compressing objects: 100% (13/13), done.
372 -remote: Total 15 (delta 3), reused 0 (delta 0)
373 -Receiving objects: 100% (15/15), done.
374 -Resolving deltas: 100% (3/3), done.
375 -$ cd turing2
376 -{{/noformat}}
377 -
378 -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.
379 -)))
380 -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.
381 -1. (((
382 -Push the new commit to the server:
383 -
384 -{{noformat}}
385 -$ git push
386 -Counting objects: 5, done.
387 -Delta compression using up to 16 threads.
388 -Compressing objects: 100% (3/3), done.
389 -Writing objects: 100% (3/3), 362 bytes, done.
390 -Total 3 (delta 1), reused 0 (delta 0)
391 -remote: => Syncing Gitorious... [OK]
392 -To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
393 - 8af2d50..1d1577f master -> master
394 -{{/noformat}}
395 -
396 -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}}:
397 -
398 -{{noformat}}
399 -$ more .git/config
400 -[core]
401 - repositoryformatversion = 0
402 - filemode = true
403 - bare = false
404 - logallrefupdates = true
405 -[remote "origin"]
406 - fetch = +refs/heads/*:refs/remotes/origin/*
407 - url = git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
408 -[branch "master"]
409 - remote = origin
410 - merge = refs/heads/master
411 -{{/noformat}}
412 -
413 -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}}.
414 -)))
415 -1. (((
416 -Go back to the original local repository and check out the {{code language="none"}}master{{/code}} branch:
417 -
418 -{{noformat}}
419 -$ cd ../turing
420 -$ git checkout master
421 -Switched to branch 'master'
422 -{{/noformat}}
423 -)))
424 -1. (((
425 -Merge the {{code language="none"}}sketches{{/code}} branch into {{code language="none"}}master{{/code}}:
426 -
427 -{{noformat}}
428 -$ git merge sketches
429 -Updating 8af2d50..21d5ddb
430 -Fast-forward
431 - examples.txt | 5 +++++
432 - notes.txt | 1 +
433 - 2 files changed, 6 insertions(+), 0 deletions(-)
434 -{{/noformat}}
435 -
436 -Now your local {{code language="none"}}master{{/code}} branch and the one on the server-side repository have diverged
437 -)))
438 -1. (((
439 -Fetch the server-side changes:
440 -
441 -{{noformat}}
442 -$ git fetch gitorious
443 -remote: Counting objects: 5, done.
444 -remote: Compressing objects: 100% (3/3), done.
445 -remote: Total 3 (delta 1), reused 0 (delta 0)
446 -Unpacking objects: 100% (3/3), done.
447 -From git.rtsys.informatik.uni-kiel.de:personal-msp/turing
448 - 8af2d50..1d1577f master -> gitorious/master
449 -{{/noformat}}
450 -
451 -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}}:
452 -
453 -{{noformat}}
454 -$ git branch -a
455 -* master
456 - sketches
457 - remotes/gitorious/master
458 -{{/noformat}}
459 -
460 -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.
461 -)))
462 -1. (((
463 -You can merge the remote changes into your local {{code language="none"}}master{{/code}} branch with the following command:
464 -
465 -{{noformat}}
466 -$ git merge gitorious/master
467 -Auto-merging examples.txt
468 -Merge made by recursive.
469 - examples.txt | 8 ++++----
470 - 1 files changed, 4 insertions(+), 4 deletions(-)
471 -{{/noformat}}
472 -
473 -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}}.
474 -)))
475 -1. (((
476 -Push the merged branch to the server, and then push the {{code language="none"}}sketches{{/code}} branch, which is not on the server yet:
477 -
478 -{{noformat}}
479 -$ git push gitorious master
480 -Counting objects: 23, done.
481 -Delta compression using up to 16 threads.
482 -Compressing objects: 100% (14/14), done.
483 -Writing objects: 100% (14/14), 1.65 KiB, done.
484 -Total 14 (delta 4), reused 0 (delta 0)
485 -remote: => Syncing Gitorious... [OK]
486 -To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
487 - 1d1577f..957f686 master -> master
488 -$ git push gitorious sketches
489 -Total 0 (delta 0), reused 0 (delta 0)
490 -remote: => Syncing Gitorious... [OK]
491 -To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
492 - * [new branch] sketches -> sketches
493 -{{/noformat}}
494 -)))
495 -1. (((
496 -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:
497 -
498 -{{noformat nopanel="true"}}
499 -TODO: formal definition
500 -{{/noformat}}
501 -)))
502 -1. (((
503 -Trying to push this commit to the server results in the following error message:
504 -
505 -{{noformat}}
506 -$ git push
507 -To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
508 - ! [rejected] master -> master (non-fast-forward)
509 -error: failed to push some refs to 'git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git'
510 -To prevent you from losing history, non-fast-forward updates were rejected
511 -Merge the remote changes before pushing again. See the 'Note about
512 -fast-forwards' section of 'git push --help' for details.
513 -{{/noformat}}
514 -
515 -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}}.
516 -)))
517 -1. (((
518 -The solution is to apply the {{code language="none"}}pull{{/code}} command followed by the {{code language="none"}}push{{/code}} command:
519 -
520 -{{noformat}}
521 -$ git pull
522 -remote: Counting objects: 23, done.
523 -remote: Compressing objects: 100% (14/14), done.
524 -remote: Total 14 (delta 4), reused 0 (delta 0)
525 -Unpacking objects: 100% (14/14), done.
526 -From git.rtsys.informatik.uni-kiel.de:personal-msp/turing
527 - 1d1577f..957f686 master -> origin/master
528 - * [new branch] sketches -> origin/sketches
529 -Auto-merging notes.txt
530 -Merge made by recursive.
531 - examples.txt | 5 +++++
532 - notes.txt | 1 +
533 - 2 files changed, 6 insertions(+), 0 deletions(-)
534 -$ git push
535 -Counting objects: 10, done.
536 -Delta compression using up to 16 threads.
537 -Compressing objects: 100% (6/6), done.
538 -Writing objects: 100% (6/6), 673 bytes, done.
539 -Total 6 (delta 2), reused 0 (delta 0)
540 -remote: => Syncing Gitorious... [OK]
541 -To git@git.rtsys.informatik.uni-kiel.de:personal-msp/turing.git
542 - 957f686..b58ded7 master -> master
543 -{{/noformat}}
544 -
545 -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.
546 -)))
547 -1. (((
548 -In order to check out the {{code language="none"}}sketches{{/code}} branch, which was previously pushed to the server, simply type the following command:
549 -
550 -{{noformat}}
551 -$ git checkout sketches
552 -Branch sketches set up to track remote branch sketches from origin.
553 -Switched to a new branch 'sketches'
554 -{{/noformat}}
555 -
556 -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.
557 -)))
558 -
559 -The {{code language="none"}}master{{/code}} branch should look like this:
560 -
561 -[[image:attach:turing-graph-02.png]]
562 -
563 -
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -2982157
1 +2982148
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982157/Git
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982148/Git