6. SCM distribuito (esempio centralizzato)
Dev #1
Dev #2
Working
copy
Working
copy
Central
repo
Local
repo
Local
repo
Intro
3/24
7. SCM distribuito: vantaggi (alcuni)
• Connettività non blocca il lavoro
• Operazioni in locale rapide
• Lavorare in privato, poi decidere cosa pubblicare
• No single point of failure
Intro
4/24
8. Installazione
• Installer/pacchetto per tutti i sistemi operativi
• No server, no demoni/servizi in background
• Configurare username e email
Repo locale
5/24
9. Creazione di un repo
• Immediato, no richiesta a sys admin
• Cartella [.git]: il repo è tutto lì!
Repo locale
6/24
git init crea il repository
10. Preparazione di un commit
• Commit = instantanea del mio progetto
• Passaggio intermedio: staging area (o index)
Repo locale
7/24
git add
git reset
aggiunge allo stage
ripulisce lo stage
11. Creazione del commit
• Attributi del commit
• Parent: commit da cui è stato creato
• Hash: identificativo universale del commit
• …
• HEAD: puntatore al commit corrente
git commit crea… il commit
Repo locale
8/24
12. Esaminare il repository
git status mostra stato working directory e stage
Repo locale
9/24
git log mostra storico dei commit
git checkout carica un commit presente nel repo
14. Annullare le modifiche
git revert <commit>
annullo modifiche di un unico commit
aggiungendo un nuovo commit
git reset <commit>
sposto il branch corrente al commit desiderato
scartando i commit
Repo locale
11/24
Non distruttivo
Distruttivo
16. Branch
• branch
• staccarsi dalla linea di sviluppo principale
• lavorare su una nuova linea indipendente
• In git: branch == puntatore ad un commit
• master è il default branch
Repo locale
13/24
17. Creare un branch
git branch
crea/rimuove un branch
git checkout <branch>
sposta HEAD su un branch
Repo locale
14/24
18. Merge di un branch
• Fast-forward: sposta il puntatore in avanti
• 3-way merge: crea un nuovo commit con due genitori
git merge unisce due branch
Repo locale
15/24
22. Sync
19/24
Repository remoti
• repo sono mondi isolati, che possono sincronizzarsi
• remote: link ad altro repo con il quale posso sincronizzare
• origin: nome default repo remoto
• bare repo: repo senza working folder
git remote
aggiunge/rimuove un repo remoto
23. Inviare ad un repo remoto
Sync
20/24
git push allinea branch remoto al branch locale (inviando commit)
prima dopo
25. Ricevere da un repo remoto
Sync
22/24
git clone clona un intero repo remoto
git fetch importa i commit da un repo remoto nel repo locale
git pull allinea branch locale ad un branch remoto (fetch + merge)