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ón | Significado |
|---|---|
| --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 |
Ejemplos
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
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