Ver un archivo en una rama Git diferente sin cambiar ramas


¿Es posible abrir un archivo en una rama de git sin revisar esa rama? ¿Cómo?

Esencialmente quiero poder abrir un archivo en mi rama github pages sin cambiar de rama todo el tiempo. No quiero modificarlo, solo quiero verlo.

Author: Gilles, 2011-10-22

4 answers

Esto debería funcionar:

git show branch:file

Donde branch puede ser cualquier ref (branch, tag, HEAD,...) yfile es la ruta completa del archivo. Para exportarlo se puede utilizar

git show branch:file > exported_file

También deberías mirar las respuestas de VonC a algunas preguntas relacionadas:

ACTUALIZACIÓN 2015-01-19:

Hoy en día puede usar rutas relativas con git show a1b35:./file.txt.

 657
Author: Scolytus,
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-05-23 12:18:16
git show somebranch:path/to/your/file

También puede hacer varios archivos y hacerlos concatenar:

git show branchA~10:fileA branchB^^:fileB

Debe proporcionar la ruta completa al archivo.

Si desea obtener el archivo en el directorio local (revertir solo un archivo) puede checkout:

git checkout somebranch^^^ -- path/to/file
 40
Author: Adam Dymitruk,
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
2011-10-22 00:01:58

Una forma sencilla y amigable para los novatos de buscar en un archivo: git gui browser <branch> que le permite explorar el contenido de cualquier archivo.

También está en el menú Archivo de git gui. La mayoría de los otros - más avanzados-envoltorios GUI (Qgit, Egit, etc..) ofrecer navegación / abrir archivos también.

 28
Author: inger,
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
2011-10-22 01:32:03

Si está utilizando Emacs, puede escribir C-x v ~ para ver una revisión diferente del archivo que está editando actualmente (todas las etiquetas, ramas y hashes funcionan).

 18
Author: legoscia,
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
2013-02-14 23:55:04