2011-05-16 15 views

Respuesta

14

Usted puede hacer lo siguiente:

git show experiment:docs/README.txt > /tmp/exported-README.txt 

... por una rama local de experiment. Para una rama que está en el repositorio que usted se refiere con el control remoto origin, puede hacer lo siguiente, de manera similar:

git fetch origin 
git show origin/other-experiment:docs/README.txt > /tmp/exported-README-remote.txt 
2

Usted puede elegir de revisar un archivo específico desde una referencia:

git checkout branch_or_hash path/to/file

La rama actual seguirá siendo el mismo, pero el otro archivo también estará presente. También se agregará al índice.

+0

Supuse que por "exportación", el PO significaba poner una copia en otro lugar y dejar copia de trabajo del repositorio y el índice como lo eran antes. Veremos, supongo :) –

+0

Ah, creo que tu interpretación tiene más sentido. – Bruno

3

git show remote/branchname:path/to/file 

Si desea guardar directamente, esto podría venir bien:

git_showfile() 
{ 
    if [ $# -lt 1 ]; then 
     return 255; 
    fi; 
    local fspec="$1"; 
    shift; 
    local fname="$(basename "$fspec")"; 
    local fpath="$(dirname "$fspec")"; 
    local revision=HEAD; 
    if [ $# -ge 1 ]; then 
     revision="$1"; 
    fi; 
    if [ -e "$fspec" ]; then 
     echo not overwriting existing file; 
    else 
     mkdir -pv "$fpath" && git show "$revision:$fspec" > "$fspec"; 
    fi 
} 

Editar: ... el que se usaría de la siguiente manera

git_showfile path/to/file 

o

git_showfile path/to/file 237f723edcb89 

etc.

Cuestiones relacionadas