Comando Git para mostrar el id de confirmación de HEAD?
¿Qué comando puedo usar para imprimir el id de confirmación de HEAD?
Esto es lo que estoy haciendo a mano:
$ cat .git/HEAD
ref: refs/heads/v3.3
$ cat .git/refs/heads/v3.3
6050732e725c68b83c35c873ff8808dff1c406e1
Pero necesito un script que pueda canalizar confiablemente la salida de algún comando a un archivo de texto de tal manera que el archivo de texto contenga exactamente el id de confirmación de HEAD (nada más o menos, y no solo un ref). Alguien puede ayudar?
7 answers
Utilice el comando:
git rev-parse HEAD
Para la versión corta:
git rev-parse --short HEAD
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-29 13:56:08
git log -1
Para solo commit id
git log | head -n 1
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-07 15:44:44
Hilo antiguo, todavía para referencia futura...:) incluso siguientes obras
git show-ref --head
De forma predeterminada, HEAD se filtra. Sin embargo, tenga cuidado al seguir ; plural "cabezas" con una 's' al final. El siguiente comando muestra las ramas bajo "refs / heads"
git show-ref --heads
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-05 13:21:23
Juega con Bash:
git show HEAD | sed -n 1p | cut -d " " -f 2
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-15 16:20:19
Según https://git-scm.com/docs/git-log, para obtener una salida más bonita en la consola, puede usar decorate decorate argumento de git-log comando:
git log --pretty=oneline --decorate
Se imprimirá:
2a5ccd714972552064746e0fb9a7aed747e483c7 (HEAD -> master) New commit
fe00287269b07e2e44f25095748b86c5fc50a3ef (tag: v1.1-01) Commit 3
08ed8cceb27f4f5e5a168831d20a9d2fa5c91d8b (tag: v1.1, tag: v1.0-0.1) commit 1
116340f24354497af488fd63f4f5ad6286e176fc (tag: v1.0) second
52c1cdcb1988d638ec9e05a291e137912b56b3af test
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-17 07:17:30
Puede especificar git log
opciones para mostrar solo la última confirmación, -1
, y un formato que incluya solo el ID de confirmación, como este:
git log -1 --format=%H
Si prefiere el ID de confirmación abreviado:
git log -1 --format=%h
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-25 20:36:46
git rev-parse --abbrev-ref HEAD
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-15 19:54:08