git checkout
git
Syntaxe
git checkout <branch> | git checkout -b <new> | git checkout -- <file>L'ancienne commande qui change de branche et restaure des fichiers, scindée en switch et restore dans git 2.23 ; checkout -- <fichier> efface définitivement les modifications non commitées.
Options courantes
| Option | Signification |
|---|---|
| -b <new> | create the branch and switch to it |
| -B <new> | create or reset it to the current commit |
| -- <file> | overwrite the file with the staged version, losing your edits |
| --track <remote>/<branch> | start a local branch that follows a remote one |
| --detach | sit on a commit with no branch attached |
| -f | throw away local changes to switch anyway |
Exemples
git checkout -b feature/loginbranches off the current commit and moves there
git checkout mainswitches branch, same as git switch main
git checkout -- src/app.tsdiscards uncommitted edits to that file; they are gone
Ce qui embrouille, c’est qu’annuler a plusieurs formes : déplacer là où pointe une branche n’est pas ajouter un commit qui l’inverse.
Comment lire
- Les crochets [ ] marquent une partie facultative.
- Les points de suspension … signifient qu’on peut en mettre plusieurs.
- Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.
Questions fréquentes
Q. Que fait git checkout ?
L'ancienne commande qui change de branche et restaure des fichiers, scindée en switch et restore dans git 2.23 ; checkout -- <fichier> efface définitivement les modifications non commitées.
Q. Comment l’écrire ?
git checkout <branch> | git checkout -b <new> | git checkout -- <file> — les crochets marquent ce qui est facultatif.
Q. Combien d’options valent la peine ?
Il y en a 6 ici ; la liste complète est dans man git. Cette commande relève de git.
Commandes liées
page man: man git-checkout