Show last authors
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
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
5 = Creating Commits =
6
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).
8 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"]].
9 1. (((
10 Configure your name and email address (will be included in all commits you create):
11
12 {{noformat}}
13 $ git config --global --add user.name "Your Name"
14 $ git config --global --add user.email "<login>@informatik.uni-kiel.de"
15 {{/noformat}}
16 )))
17 1. (((
18 Create a local repository for the "//Turing Project//":
19
20 {{noformat}}
21 $ mkdir turing
22 $ cd turing
23 $ git init
24 Initialized empty Git repository in ~/turing/.git/
25 {{/noformat}}
26 )))
27 1. (((
28 Add and commit some content: copy [[attach:notes.txt]]{{code language="none"}}{{/code}} to your {{code language="none"}}turing{{/code}} directory.
29
30 {{noformat}}
31 $ git add notes.txt
32 $ git commit -m "wrote some first notes"
33 [master (root-commit) 2e73b34] wrote some first notes
34 1 files changed, 5 insertions(+), 0 deletions(-)
35 create mode 100644 notes.txt
36 {{/noformat}}
37 )))
38 1. Edit {{code language="none"}}notes.txt{{/code}}:\\
39 11. Replace "fixed" with "infinite" in line 1.
40 11. Replace "... (TODO)" with "a finite state machine" in line 4.
41 1. (((
42 View the status of your current working copy:
43
44 {{noformat}}
45 $ git status
46 # On branch master
47 # Changed but not updated:
48 # (use "git add <file>..." to update what will be committed)
49 # (use "git checkout -- <file>..." to discard changes in working directory)
50 #
51 # modified: notes.txt
52 #
53 no changes added to commit (use "git add" and/or "git commit -a")
54 {{/noformat}}
55 )))
56 1. (((
57 Mark the modified file to include it in the next commit, then view the status again and compare with the previous output:
58
59 {{noformat}}
60 $ git add notes.txt
61 $ git status
62 # On branch master
63 # Changes to be committed:
64 # (use "git reset HEAD <file>..." to unstage)
65 #
66 # modified: notes.txt
67 #
68 {{/noformat}}
69 )))
70 1. (((
71 Commit the modified content to your local repository and view the status:
72
73 {{noformat}}
74 $ git commit -m "modified tape length, found a controller for tape head"
75 [master 52e2d49] modified tape length, found a controller for tape head
76 1 files changed, 2 insertions(+), 2 deletions(-)
77 $ git status
78 # On branch master
79 nothing to commit (working directory clean)
80 {{/noformat}}
81 )))
82
83 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:
84
85 {{noformat}}
86 $ git log
87 commit 52e2d4946791c2725015853e5e261ce143c6fe8a
88 Author: Miro Spoenemann <msp@informatik.uni-kiel.de>
89 Date: Mon Oct 15 15:00:14 2012 +0200
90
91 modified tape length, found a controller for tape head
92
93 commit 2e73b34ac44480773fc0e52875b7353a087d8c6d
94 Author: Miro Spoenemann <msp@informatik.uni-kiel.de>
95 Date: Mon Oct 15 12:14:06 2012 +0200
96
97 wrote some first notes
98  
99 $ git show 52e2d49
100 commit 52e2d4946791c2725015853e5e261ce143c6fe8a
101 Author: Miro Spoenemann <msp@informatik.uni-kiel.de>
102 Date: Mon Oct 15 15:00:14 2012 +0200
103
104 modified tape length, found a controller for tape head
105
106 diff --git a/notes.txt b/notes.txt
107 index 4ded2b3..bd422b3 100644
108 --- a/notes.txt
109 +++ b/notes.txt
110 @@ -1,5 +1,5 @@
111 - * A tape with fixed length
112 + * A tape with infinite length
113 * Tape head can read or write data
114 * Tape head can move left or right
115 - * The head is controlled by ... (TODO)
116 + * The head is controlled by a finite state machine
117 {{/noformat}}
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.