aboutsummaryrefslogtreecommitdiff
path: root/introduzione_a_git.rest
blob: f866f780cc1cc4950ec246eb7a90f9701115c801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
Introduzione a GIT
==================

.. footer:: LIFO

.. contents::
   :class: handout

Un nuovo progetto
-----------------

.. class:: handout

   Iniziamo un nuovo progetto che vogliamo salvare sotto git: non serve 
   preoccuparsi di avere un server, e neanche un nome pubblicabile 
   per il progetto, basta creare una directory (che potremo rinominare 
   in futuro), dire a git di crearci un repository e poi si può inizare 
   subito a lavorare.

::

   $ mkdir greeter
   $ cd greeter/
   $ git init
   Initialized empty Git repository in /home/[...]/greeter/.git/

Qualche file
------------

.. class:: handout

   Creiamo i nostri file, in questo caso un programma in python 
   che saluterà le persone.

::

   $ mkdir greeter
   $ touch greeter/__init__.py
   $ cat > greeter/greeter.py
   class Greeter:
       """ """
   $ cat > greeter.py
   #!/usr/bin/env python

   def main():
       pass

   if __name__ == '__main__': main()
   $ chmod 755 greeter.py


GIT
---

.. class:: handout

   Con ``git status`` possiamo vedere che git si è accorto dell'esistenza 
   di alcuni file, ma sono *untracked*, ovvero non considerati 
   dal controllo delle revisioni.

::

   $ git status
   # On branch master
   #
   # Initial commit
   #
   # Untracked files:
   #   (use "git add <file>..." to include in what will be committed)
   #
   #       greeter.py
   #       greeter/
   nothing added to commit but untracked files present (use "git add" to track)


In staging
----------

.. class:: handout

   Aggiungiamo quel che abbiamo fatto alla *staging area*, ovvero 
   diciamo a git di prendere in considerazione quella versione 
   del file perché venga successivamente salvata.

::
   
   $ git add greeter.py greeter/
   $ git status
   # On branch master
   #
   # Initial commit
   #
   # Changes to be committed:
   #   (use "git rm --cached <file>..." to unstage)
   #
   #       new file:   greeter.py
   #       new file:   greeter/__init__.py
   #       new file:   greeter/greeter.py
   #

Altre mod
---------

.. class:: handout

   Facendo altre modifiche e riguardando ``git status`` ci possiamo 
   accorgere di come git non salvi automaticamente tutti i cambiamenti 
   presenti nei file di cui tiene traccia, ma solo quelli che gli
   vengono indicati esplicitamente da salvare.

::

   $ cat > greeter/__init__.py
   from greeter import Greeter
   $ git status
   # On branch master
   #
   # Initial commit
   #
   # Changes to be committed:
   #   (use "git rm --cached <file>..." to unstage)
   #
   #       new file:   greeter.py
   #       new file:   greeter/__init__.py
   #       new file:   greeter/greeter.py
   #
   # Changes not staged for commit:
   #   (use "git add <file>..." to update what will be committed)
   #   (use "git checkout -- <file>..." to discard changes in working directory)
   #
   #       modified:   greeter/__init__.py
   #


Commit
------

.. class:: handout

   Finalmente possiamo aggiungere anche le ultime modifiche:

::
   
   $ git add greeter/__init__.py
   $ git commit


.. class:: handout

   Se è la prima volta che usiamo git su questo computer salviamo qualche 
   informazione su di noi, nel mio caso:

::

   $ git config --global user.name "Elena ``of Valhalla'' Grandi"
   $ git config --global user.email valhalla@trueelena.org

.. class:: handout

   E finalmente possiamo creare il nostro primo commit, un insieme 
   di file in una loro determinata versione al quale vengono associati 
   alcuni metadati (autore, data, ...) e soprattutto un identificativo 
   che è un hash crittografico dei contenuti.

   Il comando ``git commit`` apre un editor con il quale scrivere 
   un commento da associare al commit. Di solito si scrive una descrizione 
   breve da una riga (una 60ina di caratteri), e poi eventualmente 
   altre informazioni più approfondite.

::

   Skeleton for the new project.
   # Please enter the commit message for your changes. Lines starting
   # with '#' will be ignored, and an empty message aborts the commit.
   # On branch master
   #
   # Initial commit
   #
   # Changes to be committed:
   #   (use "git rm --cached <file>..." to unstage)
   #
   #       new file:   greeter.py
   #       new file:   greeter/__init__.py
   #       new file:   greeter/greeter.py
   #

::
   
   ".git/COMMIT_EDITMSG" 14L, 377C written
   [master (root-commit) b54e94f] Skeleton for the new project.
    3 files changed, 9 insertions(+)
    create mode 100755 greeter.py
    create mode 100644 greeter/__init__.py
    create mode 100644 greeter/greeter.py


LOG
---

::

   $ git log
   commit b54e94fde972281ca31a56ef0d36204addd4906b
   Author: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
   Date:   Thu Nov 15 19:05:42 2012 +0100

       Skeleton for the new project.



Iniziamo a lavorarci
--------------------

``greeter/greeter.py``::

   class Greeter:
       """ """

       def greet(self):
           print "Hello World!"

``greeter.py``::

   #!/usr/bin/env python

   import greeter

   def main():
       grt = greeter.Greeter()
       grt.greet()

   if __name__ == '__main__': main()

Diamo in pasto a git
--------------------

::

   $ git add greeter.py greeter/greeter.py
   $ git commit -m 'Generic greetings'
   [master adfbc73] Generic greetings
    2 files changed, 8 insertions(+), 1 deletion(-)
   $ git status
   # On branch master
   nothing to commit (working directory clean)
   $ git log
   commit adfbc7340ac1af8b1dc80ebb1526c7b2b9ad4d1f
   Author: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
   Date:   Thu Nov 15 19:08:29 2012 +0100

       Generic greetings

   commit b54e94fde972281ca31a56ef0d36204addd4906b
   Author: Elena ``of Valhalla'' Grandi <valhalla@trueelena.org>
   Date:   Thu Nov 15 19:05:42 2012 +0100

       Skeleton for the new project.

gitignore
---------

Aggiungere funzionalità
-----------------------

Che bel sole là fuori!
----------------------

Ora di rientrare
----------------

Un bel backup
-------------


Finalmente pubblichiamo
-----------------------

::

   $ $BROWSER http://gitorious.org

Non github?
-----------

Alternative:

* <http://repo.or.cz/>_
* gitolite_ + gitweb_ self-hosted
* ...

.. _gitolite: 
.. _gitweb: 

..
   vim: set filetype=rst: