From ef87fab668e0c6af8bc22ff3fffb218ea91a8ebc Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Tue, 20 Feb 2024 16:43:29 +0100 Subject: [PATCH] =?UTF-8?q?Pr=C3=A9cisions=20sur=20les=20commandes=20d'ann?= =?UTF-8?q?ulation.=20refs=20#12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01_initiation/04_ligne de commande_complet.md | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/01_initiation/04_ligne de commande_complet.md b/01_initiation/04_ligne de commande_complet.md index 1fabc17..653415f 100644 --- a/01_initiation/04_ligne de commande_complet.md +++ b/01_initiation/04_ligne de commande_complet.md @@ -270,13 +270,38 @@ git diff ---vertical--- -Si l'on souhaite supprimer **toutes** les modifications non commitées +Pour annuler les modifications non commitées et indexées. ```bash git reset -- mon_fichier.txt ``` + ---vertical--- + +Pour annuler les modifications non commitées et non indexées (retrouver le fichier de l'index ou d'un autre commit). + +```bash +git checkout -- mon_fichier.txt +# ou +git restore mon_fichier.txt +``` + +Note: +- [Reset, restore and revert](https://git-scm.com/docs/git#_reset_restore_and_revert) +- pour `checkout` : https://git-scm.com/book/fr/v2/Les-bases-de-Git-Annuler-des-actions#_r%C3%A9initialiser_un_fichier_modifi%C3%A9 +- pour `restore` : https://git-scm.com/book/fr/v2/Les-bases-de-Git-Annuler-des-actions#undoing_git_restore + ---vertical--- + +Pour désindexer un fichier modifié et indexé. + +```bash +git restore --staged mon_fichier.txt +``` + +Note: +Désindexer (*unstage*) c'est passer de l'indexe (*Staging area*) ([diapo 3](https://git-gitlab-paca.pages.mia.inra.fr/support-de-formation/01_initiation/#/3)) au dossier de travail (*Working directory*), soit l'inverse de `git add`. Il n'y a pas encore eu de commit. + ---vertical--- # Grouper un commit avec un commit précédent -- GitLab