Inicio·Comandos de terminal

git rev-parse

git

Uso

git rev-parse [--short] <rev>

Convierte un nombre como HEAD o v1.2.0^ en un hash real y dice dónde está el repositorio; los scripts obtienen la rama con --abbrev-ref HEAD, y fuera de un repositorio termina con error.

Opciones habituales

OpciónSignificado
--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

Ejemplos

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

Lo confuso es que deshacer tiene varias formas: mover a dónde apunta una rama no es lo mismo que añadir un commit que la revierte.

Cómo leerlo

  • Los corchetes [ ] marcan una parte que puedes omitir.
  • Los puntos suspensivos … indican que puedes poner varios.
  • Las opciones distinguen mayúsculas: en algunos comandos -r y -R no hacen lo mismo.

Preguntas

Q. ¿Qué hace git rev-parse?

Convierte un nombre como HEAD o v1.2.0^ en un hash real y dice dónde está el repositorio; los scripts obtienen la rama con --abbrev-ref HEAD, y fuera de un repositorio termina con error.

Q. ¿Cómo se escribe?

git rev-parse [--short] <rev> — los corchetes marcan lo que puedes omitir.

Q. ¿Cuántas opciones vale la pena saber?

Aquí van 6; la lista completa está en man git. Este comando está en git.

Comandos relacionados

página man: man git-rev-parse