Diff en français
Introduction au Commande Diff
Le commande diff est un outil crucial dans le monde de Git, servant à afficher les modifications apportées dans les différents éléments de l'environnement de travail : fichiers, répertoires, commits et même branches. En d'autres termes, diff
permet de visualiser les changements effectués sur un ou plusieurs éléments dans un dépôt.
Syntaxe du Commande Diff
La syntaxe de base pour comparer les changements dans un dépôt en utilisant diff
est la suivante :
git diff
Utilisations du Commande Diff
Il existe plusieurs façons d'utiliser la commande git diff
.
- Comparer le répertoire de travail avec la zone de staging Lorsque la commande est utilisée sans options, elle affiche les différences entre le répertoire de travail et la zone de staging. Par exemple, supposons que le fichier
scene.txt
contient déjà une version initiale enregistrée :
scene.txt (version initiale)plaintext COBBYTO: In a dream, brain activity will be roughly thirty times higher than usual. The effect is increased by entering a dream within that dream. ARIANEA: How long should each level take?
Si le fichier scene.txt
est modifié comme suit :
scene.txt (version modifiée)plaintext COBBYTO: In a dream, brain activity will be roughly thirty times higher than usual. The effect is increased by entering a dream within that dream. ARIANEA: How long? COBBYTO: According to my calculations, the time span is approximately three days at the top layer, three months one layer down, and six years a level after. ARIANEA: Who would want to live in an illusory world for six years?
En exécutant git diff
, vous obtiendrez la sortie suivante :bash $ git diff diff --git a/scene.txt b/scene.txt index c16c37f..c680bb4 100644 --- a/scene.txt +++ b/scene.txt @@ -2,4 +2,10 @@ COBBYTO: In a dream, brain activity will be roughly thirty times higher than usual. The effect is increased by entering a dream within that dream. -ARIANEA: How long? +ARIANEA: How long? +COBBYTO: According to my calculations, the time span is approximately three days at the top layer, three months one layer down, and six years a level after. +ARIANEA: Who would want to live in an illusory world for six years?
- Comparer la zone de staging avec le dernier commit
La commandegit diff --cached
affiche les changements entre la zone de staging et le dernier commit. Lorsque vous exécutezgit diff --cached
sans rien avoir ajouté à la zone de staging, aucune sortie ne sera affichée, car il n'y a aucun changement à signaler. Cela peut être vérifié avecgit status
:bash $ git status Sur la branche master Changements non stagés pour le commit : (utilisez "git add <file>..." pour mettre à jour ce qui sera commit) (utilisez "git checkout -- <file>..." pour abandonner les changements dans le répertoire de travail) modifié : scene.txt Aucune changement ajoutée au commit (utilisez "git add" et / ou "git commit -a")
En ajoutantscene.txt
à la zone de staging et en exécutantgit diff --cached
, vous verrez alors :bash $ git diff --cached diff --git a/scene.txt b/scene.txt index c16c37f..c680bb4 100644 --- a/scene.txt +++ b/scene.txt @@ -2,4 +2,10 @@ COBBYTO: In a dream, brain activity will be roughly thirty times higher than usual. The effect is increased by entering a dream within that dream. -ARIANEA: How long? +ARIANEA: How long? +COBBYTO: According to my calculations, the time span is approximately three days at the top layer, three months one layer down, and six years a level after. +ARIANEA: Who would want to live in an illusory world for six years?
La sortie sera identique à celle obtenue avecgit diff
car les changements déjà enregistrés ont été ajoutés à la zone de staging.