Accueil·Commandes du terminal

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

OptionSignification
--short[=<n>]abbreviate the hash
--abbrev-ref HEADprint the current branch name
--show-toplevelprint the root of the working tree
--git-dirprint the path of the .git directory
--is-inside-work-treetrue or false, for scripts
--verify <rev>fail loudly if the name does not resolve

Exemples

git rev-parse --short HEAD

the short hash a build should stamp itself with

git rev-parse --abbrev-ref HEAD

the branch name, for a CI script

git rev-parse --show-toplevel

the 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