SlideShare a Scribd company logo
Git
A cura di Mario Vitale
System Developer & System Integrator
Napoli: NaLUG – Talk 16/05/2020
Panoramica
Git, questo sconosciuto
● Software per repository con version control
● Creato nel 2005 da Linus Torvalds
● Ottimizzato per POSIX
● Realizza un filesystem “distribuito”
Filesystem Distribuito
Filesystem:
● Non distingue i file per tipologia
● Utilizza access right propri
● I contenuti sono oggetti
● Indicizzazione propria degli oggetti
Distribuito:
● Non usa un server centralizzato
● Predisposto per la collaborazione con
terzi
Repository vs Hosting
Hands-on: installazione Git
Aggiungere il repo (se necessario):
● sudo add-apt-repository ppa:git-core/ppa
Installare Git:
● sudo apt update
● sudo apt install git
Check
● git --version
● which git
Hands-on: inizializzare un progetto
Creare la working folder:
● cd ~
● mkdir myproject
Creare il repository:
● git init
Configurare
● git config --global user.name <nome>
● git config --global user.email <email>
Analizzare:
● ls -la
● cd .git
● cd object
● ls
Creare file nella working dir:
● cd ~/myproject
● touch file1.txt
Analizzare:
● git status
● Eventualmente cartella object
Staging e check
● git add file1.txt
● cd .git/objects
● git ls-files
Commit e check
git commit
cd .git/objects
Workspaces
Workspaces e comandi
File lifecycle
Objects
Blob Tree Commit Annotated
Tag
Dentro gli objects
Hash
0a2b198f595e55060dec9f0e196c10de86f2ca1c
SHA1
Caratteristiche:
● 160 bit
● Output a 40 caratteri esadecimali: 160/4
● 2^160 combinazioni possibili
● 2^160 file possibili per repository
● SHA1 eseguito sugli oggetti, non sui file
Tree object
Costituito da:
● Permessi
● Tipo object
● Hash dell’object (contenente il file): puntatore
● Tabulazione
● Nome originale del file
Commit object
Costituito da:
● Hash dell’oggetto tree cui punta
● Nome di autore e commiter
● E-mail di autore e commiter
● Hash del commit parent (se non è un primo commit)
● Timestamp del commit in UTC
● Dati autore configurati globalmente o per progetto
Hands-on: oggetti
Check del commit:
● cd .git/objects
● git cat-file -t <hash>
● git cat-file -p <hash>
Aggiungere nuovo file
● Come prima
Analizzare:
● Come prima
Esempio struttura
Ogni oggetto ha un hash che lo identifica
I puntatori sono hash
HEAD e Master
Checkout Branch
Detached HEAD state
Merge: fast-forward (1)
Merge: fast-forward (2)
Hands-on: branch & FF merge
Check e creazione branch:
● git branch
● git branch feature1
Operare sul nuovo branch:
● git checkout feature1
● git branch
● touch file4.txt
● nano file1.txt (modificare)
● git add .
● git commit
● git log (anche i log del vecchio branch)
Merge:
● git checkout master
● git merge feature1
● git log
Merge: 3-way merge (1)
Merge: 3-way merge (2)
Hands-on: branch & 3-way merge
Creazione branch:
● git branch feature2
● nano file5.txt
● git add .
● git commit
Sul nuovo branch:
● git checkout feature2
● ls
● nano file5.txt
● git add .
● git commit
Merge:
● git checkout master
● git merge feature2
● git ls-files -s
● git cat-file <hash>
● nano file5.txt
● git add .
● git commit
● git log
Rebase (1)
Rebase (2)
Hands-on: rebase
Creazione branch:
● git branch feature3
● nano file6.txt
● git add .
● git commit
Sul nuovo branch:
● git checkout feature3
● ls
● nano file7.txt
● git add .
● git commit
● nano file8.txt
● git add .
● git commit
Rebase:
● git checkout feature3
● git rebase master
● git ls-files -s
● git cat-file <hash>
● git checkout master
● git merge feature 3
● git log
Hosting Repository
● Git pull = git fetch + git checkout
● git merge FETCH_HEAD
● Git push
● Git clone
● Download
Hands-on: repository remoto
Creazione repository remoto da locale via https:
● git push --set-upstream https://gitlab.com/username/project_name.git master
● Inserimento username
● Inserimento password
Clonazione repository remoto su locale via https:
● git clone https://gitlab.com/username/project_name.git
● cat <nomepackfile>.pack | git unpack
● Clonazione != Download
.gitignore
E.g.:
● FileName.ext
● FolderName/
● *.ext
Esclusioni
● la cartella bin/: chi clona il repository può crearsela direttamente su sistema di
produzione, copiarla non sarebbe efficiente
● le cartelle delle dipendenze: sono tipicamente grandi e possono essere soddisfatte
da chi clona il repository, copiarle non è efficiente (e.g.: node_modules/).
● i file compilati
● i log
● i file creati dal sistema operativo (e.g.: Thumbs.db o DS_Store)
Link Utili
Tool grafici:
● https://gitahead.github.io/gitahead.com/
● https://wiki.gnome.org/action/show/Apps/Gitg
Riferimenti e troubleshooting
● https://git-scm.com/
● https://ohshitgit.com/

More Related Content

PPTX
Migrare da un VCS centralizzato a Git
PDF
Git in 5 minuti
PDF
Git/Continuous Integration/Docker: la terna dello sviluppo moderno.
PDF
Git best practices
PDF
Introduzione a Git
PDF
PDF
Git e GitHub
Migrare da un VCS centralizzato a Git
Git in 5 minuti
Git/Continuous Integration/Docker: la terna dello sviluppo moderno.
Git best practices
Introduzione a Git
Git e GitHub

Similar to Git (20)

PDF
Emerasoft Git quickstart
PDF
Introduzione a Git (ITA - 2017)
PPTX
Introduzione a git
PDF
Git – lo stupido gestore di contenuti
PDF
Git for dummies
PDF
Git: un'introduzione pratica
PDF
Git gestione comoda del repository
PDF
Introduzione a git
PDF
GIT SOTTO IL COFANO
PDF
Revisionare, tracciare, collaborare. Version control con git
PDF
Introduzione a Git e GitLab
PDF
Git
PDF
Introduzione a Git
PPTX
Git Flow - Un modello di branching che funziona
KEY
Corso Python Deltapromo - Lezione 3
PDF
Git branching model
KEY
ODP
Controllo di versione e Git
PDF
Git e GitHub - L'essenziale
PDF
GIT commands version control system and collaboration
Emerasoft Git quickstart
Introduzione a Git (ITA - 2017)
Introduzione a git
Git – lo stupido gestore di contenuti
Git for dummies
Git: un'introduzione pratica
Git gestione comoda del repository
Introduzione a git
GIT SOTTO IL COFANO
Revisionare, tracciare, collaborare. Version control con git
Introduzione a Git e GitLab
Git
Introduzione a Git
Git Flow - Un modello di branching che funziona
Corso Python Deltapromo - Lezione 3
Git branching model
Controllo di versione e Git
Git e GitHub - L'essenziale
GIT commands version control system and collaboration
Ad

Git

  • 1. Git A cura di Mario Vitale System Developer & System Integrator Napoli: NaLUG – Talk 16/05/2020
  • 3. Git, questo sconosciuto ● Software per repository con version control ● Creato nel 2005 da Linus Torvalds ● Ottimizzato per POSIX ● Realizza un filesystem “distribuito”
  • 4. Filesystem Distribuito Filesystem: ● Non distingue i file per tipologia ● Utilizza access right propri ● I contenuti sono oggetti ● Indicizzazione propria degli oggetti Distribuito: ● Non usa un server centralizzato ● Predisposto per la collaborazione con terzi
  • 6. Hands-on: installazione Git Aggiungere il repo (se necessario): ● sudo add-apt-repository ppa:git-core/ppa Installare Git: ● sudo apt update ● sudo apt install git Check ● git --version ● which git
  • 7. Hands-on: inizializzare un progetto Creare la working folder: ● cd ~ ● mkdir myproject Creare il repository: ● git init Configurare ● git config --global user.name <nome> ● git config --global user.email <email> Analizzare: ● ls -la ● cd .git ● cd object ● ls Creare file nella working dir: ● cd ~/myproject ● touch file1.txt Analizzare: ● git status ● Eventualmente cartella object Staging e check ● git add file1.txt ● cd .git/objects ● git ls-files Commit e check git commit cd .git/objects
  • 11. Objects Blob Tree Commit Annotated Tag
  • 13. Hash 0a2b198f595e55060dec9f0e196c10de86f2ca1c SHA1 Caratteristiche: ● 160 bit ● Output a 40 caratteri esadecimali: 160/4 ● 2^160 combinazioni possibili ● 2^160 file possibili per repository ● SHA1 eseguito sugli oggetti, non sui file
  • 14. Tree object Costituito da: ● Permessi ● Tipo object ● Hash dell’object (contenente il file): puntatore ● Tabulazione ● Nome originale del file
  • 15. Commit object Costituito da: ● Hash dell’oggetto tree cui punta ● Nome di autore e commiter ● E-mail di autore e commiter ● Hash del commit parent (se non è un primo commit) ● Timestamp del commit in UTC ● Dati autore configurati globalmente o per progetto
  • 16. Hands-on: oggetti Check del commit: ● cd .git/objects ● git cat-file -t <hash> ● git cat-file -p <hash> Aggiungere nuovo file ● Come prima Analizzare: ● Come prima
  • 17. Esempio struttura Ogni oggetto ha un hash che lo identifica I puntatori sono hash
  • 23. Hands-on: branch & FF merge Check e creazione branch: ● git branch ● git branch feature1 Operare sul nuovo branch: ● git checkout feature1 ● git branch ● touch file4.txt ● nano file1.txt (modificare) ● git add . ● git commit ● git log (anche i log del vecchio branch) Merge: ● git checkout master ● git merge feature1 ● git log
  • 26. Hands-on: branch & 3-way merge Creazione branch: ● git branch feature2 ● nano file5.txt ● git add . ● git commit Sul nuovo branch: ● git checkout feature2 ● ls ● nano file5.txt ● git add . ● git commit Merge: ● git checkout master ● git merge feature2 ● git ls-files -s ● git cat-file <hash> ● nano file5.txt ● git add . ● git commit ● git log
  • 29. Hands-on: rebase Creazione branch: ● git branch feature3 ● nano file6.txt ● git add . ● git commit Sul nuovo branch: ● git checkout feature3 ● ls ● nano file7.txt ● git add . ● git commit ● nano file8.txt ● git add . ● git commit Rebase: ● git checkout feature3 ● git rebase master ● git ls-files -s ● git cat-file <hash> ● git checkout master ● git merge feature 3 ● git log
  • 30. Hosting Repository ● Git pull = git fetch + git checkout ● git merge FETCH_HEAD ● Git push ● Git clone ● Download
  • 31. Hands-on: repository remoto Creazione repository remoto da locale via https: ● git push --set-upstream https://gitlab.com/username/project_name.git master ● Inserimento username ● Inserimento password Clonazione repository remoto su locale via https: ● git clone https://gitlab.com/username/project_name.git ● cat <nomepackfile>.pack | git unpack ● Clonazione != Download
  • 32. .gitignore E.g.: ● FileName.ext ● FolderName/ ● *.ext Esclusioni ● la cartella bin/: chi clona il repository può crearsela direttamente su sistema di produzione, copiarla non sarebbe efficiente ● le cartelle delle dipendenze: sono tipicamente grandi e possono essere soddisfatte da chi clona il repository, copiarle non è efficiente (e.g.: node_modules/). ● i file compilati ● i log ● i file creati dal sistema operativo (e.g.: Thumbs.db o DS_Store)
  • 33. Link Utili Tool grafici: ● https://gitahead.github.io/gitahead.com/ ● https://wiki.gnome.org/action/show/Apps/Gitg Riferimenti e troubleshooting ● https://git-scm.com/ ● https://ohshitgit.com/