|
|
@ -1 +1,126 @@
|
|
|
|
== De s’approprier un outil de gestion de versions
|
|
|
|
== Git !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Généralités
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[.step]
|
|
|
|
|
|
|
|
* Gestionnaire de versions distribué
|
|
|
|
|
|
|
|
* Créé par Linus Torvalds en 2005 pour la gestion des sources du noyau Linux
|
|
|
|
|
|
|
|
* Le nom "git" est une référence directe à l'auteur...
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
[quote,Linus Torvalds]
|
|
|
|
|
|
|
|
____
|
|
|
|
|
|
|
|
I'm an egotistical bastard, and I name all my projects after myself.
|
|
|
|
|
|
|
|
First Linux, now git.
|
|
|
|
|
|
|
|
____
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Fonctionnement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[.step]
|
|
|
|
|
|
|
|
* Git ne retiens pas une suite de différences, mais des snapshots des fichiers
|
|
|
|
|
|
|
|
* Pratiquement toutes les opérations sont locales
|
|
|
|
|
|
|
|
* Git ne fait pratiquement qu'àjouter des données à sa base
|
|
|
|
|
|
|
|
* Chaque utilisateur peut disposer de tous les commits
|
|
|
|
|
|
|
|
* => Serveur pas indispensable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
== Démarrer avec Git
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Installation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[.step]
|
|
|
|
|
|
|
|
* Linux : dans les paquets de toutes les distributions
|
|
|
|
|
|
|
|
* Windows : plusieurs choix
|
|
|
|
|
|
|
|
** Simple et minimaliste : https://gitforwindows.org/[Git pour Windows]
|
|
|
|
|
|
|
|
** Complexe mais puissant : https://www.cygwin.com/[Cygwin], une collection d'outils Linux compilés pour Windows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Préparation de Git
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
$ git config --global user.name "Your Name"
|
|
|
|
|
|
|
|
$ git config --global user.email "foo@bar.org"
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Créer un dépôt local
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
$ mkdir super_projet
|
|
|
|
|
|
|
|
$ cd super_projet
|
|
|
|
|
|
|
|
$ git init .
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Ajouter un premier fichier
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
$ echo "salut" > rapport.md
|
|
|
|
|
|
|
|
$ git add rapport.md
|
|
|
|
|
|
|
|
$ git commit -m "commit initial"
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== États du fichier
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[plantuml,addcommit,svg]
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
@startuml
|
|
|
|
|
|
|
|
skinparam backgroundColor #fefefe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"Espace de Travail" -> "Espace de Travail": echo "salut" > rapport.md
|
|
|
|
|
|
|
|
"Espace de Travail" -> Index: git add rapport.md
|
|
|
|
|
|
|
|
Index -> Dépôt: git commit -m "commit initial"
|
|
|
|
|
|
|
|
@enduml
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Référence utile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
https://ndpsoftware.com/git-cheatsheet.html[https://ndpsoftware.com/git-cheatsheet.html]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
== Travailler avec les branches
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Git est un graphe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//[.stretch]
|
|
|
|
|
|
|
|
[graphviz,git-graph,svg]
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
digraph g {
|
|
|
|
|
|
|
|
rankdir = LR
|
|
|
|
|
|
|
|
node[group=master];
|
|
|
|
|
|
|
|
1 -> 2 -> 3 -> 4 -> 7
|
|
|
|
|
|
|
|
node[group=branch];
|
|
|
|
|
|
|
|
2 -> 5 -> 6
|
|
|
|
|
|
|
|
node[group=refs shape=note style=filled fillcolor=yellow];
|
|
|
|
|
|
|
|
edge[arrowhead = none style=dotted]
|
|
|
|
|
|
|
|
7 -> master
|
|
|
|
|
|
|
|
6 -> relecture
|
|
|
|
|
|
|
|
master -> HEAD
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[.step]
|
|
|
|
|
|
|
|
* commit : 0 à n parent(s) + auteur + committer + message + état des fichiers
|
|
|
|
|
|
|
|
* "master", "relecture" : branche, référence à un commit
|
|
|
|
|
|
|
|
* "HEAD" : référence à la branche ou au commit sur lequel est basé l'espace de travail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Pour la culture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Allons voir les entrailles du dépôt...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[.stretch]
|
|
|
|
|
|
|
|
[source,shell]
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
$ cat .git/refs/heads/master
|
|
|
|
|
|
|
|
8b3e8234ccad7d9213bb28d1e70351ebeff965c8 # différent pour chacun
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ git cat-file -p 8b3e8234ccad7d9213bb28d1e70351ebeff965c8
|
|
|
|
|
|
|
|
tree 1ee6881b1653531a8fc24057be0c61d82b8325de
|
|
|
|
|
|
|
|
parent b4c8004bffba2d54753f906f5aa146a6d1ff4bef
|
|
|
|
|
|
|
|
author Yves Dubromelle <yves+git@dubronetwork.fr> 1587331162 +0200
|
|
|
|
|
|
|
|
committer Yves Dubromelle <yves+git@dubronetwork.fr> 1587331162 +0200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mon super message de commit
|
|
|
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== Créer une branche
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[.step]
|
|
|
|
|
|
|
|
* On veut relire
|
|
|
|