git rev-parse
git
Syntaxe
git rev-parse [--short] <rev>Traduit un nom comme HEAD ou v1.2.0^ en véritable hachage et indique où se trouve le dépôt ; les scripts récupèrent le nom de branche avec --abbrev-ref HEAD, et hors d'un dépôt la commande échoue.
Options courantes
| Option | Signification |
|---|---|
| --short[=<n>] | abbreviate the hash |
| --abbrev-ref HEAD | print the current branch name |
| --show-toplevel | print the root of the working tree |
| --git-dir | print the path of the .git directory |
| --is-inside-work-tree | true or false, for scripts |
| --verify <rev> | fail loudly if the name does not resolve |
Exemples
git rev-parse --short HEADthe short hash a build should stamp itself with
git rev-parse --abbrev-ref HEADthe branch name, for a CI script
git rev-parse --show-toplevelthe repository root, wherever you are inside it
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 rev-parse ?
Traduit un nom comme HEAD ou v1.2.0^ en véritable hachage et indique où se trouve le dépôt ; les scripts récupèrent le nom de branche avec --abbrev-ref HEAD, et hors d'un dépôt la commande échoue.
Q. Comment l’écrire ?
git rev-parse [--short] <rev> — 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-rev-parse