informatica:git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:git [2014/02/26 14:33] – [Iniciar repositorio en remoto] javi | informatica:git [2024/10/17 14:56] (current) – jose | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== git ===== | + | ====== git ====== |
| - | ==== Iniciar repositorio en remoto ==== | + | ===== Tags ===== |
| + | |||
| + | 1. Listar los commits de un repositorio | ||
| + | |||
| + | < | ||
| + | git log --pretty=oneline | ||
| + | </ | ||
| + | |||
| + | 2. Marcar con una etiqueta (en este ejemplo " | ||
| + | |||
| + | < | ||
| + | git tag -a v1.0 947c168ba5cc2c40dabe15b1a140e0a90f29f3c3 | ||
| + | </ | ||
| + | |||
| + | 3. Subir las etiquetas al repositorio remoto: | ||
| + | |||
| + | < | ||
| + | git push origin v1.0 | ||
| + | </ | ||
| + | |||
| + | ===== Iniciar repositorio en remoto | ||
| Given a project in our local file system: | Given a project in our local file system: | ||
| Line 19: | Line 39: | ||
| 4. Move the directory to its final location using SSH | 4. Move the directory to its final location using SSH | ||
| scp -rv / | scp -rv / | ||
| + | | ||
| + | ===== Subir un cambio ===== | ||
| - | ==== Comandos sueltos | + | git add < |
| + | git commit -m " | ||
| + | git push | ||
| + | ===== Añadir rama branch | ||
| + | git pull | ||
| + | git checkout -b test | ||
| + | git push origin test | ||
| + | Listar ramas: | ||
| + | < | ||
| + | git branch -a | ||
| + | master | ||
| + | * test | ||
| + | remotes/ | ||
| + | remotes/ | ||
| + | remotes/ | ||
| + | </ | ||
| + | Cambiar de rama: | ||
| + | < | ||
| + | git checkout master | ||
| + | A Dockerfile_ok | ||
| + | A Dockerfile_test | ||
| + | Switched to branch ' | ||
| + | Your branch is up to date with ' | ||
| + | </ | ||
| + | ===== Servidor git acceso claves ssh ===== | ||
| + | |||
| + | http:// | ||
| + | |||
| + | 0. (Opcional) Instalo paquetes | ||
| + | |||
| + | sudo aptitude install git | ||
| + | |||
| + | 1. Crear usuario git con el minimo de permisos posible | ||
| + | |||
| + | sudo vim /etc/shells | ||
| + | |||
| + | Y anyadir, si no existe, la siguiente linea: | ||
| + | |||
| + | / | ||
| + | |||
| + | Seguimos con la creacion del usuario " | ||
| + | |||
| + | < | ||
| + | sudo adduser git | ||
| + | sudo chsh git | ||
| + | </ | ||
| + | |||
| + | Teclear: | ||
| + | |||
| + | / | ||
| + | |||
| + | Y pulsar " | ||
| + | |||
| + | < | ||
| + | sudo su git | ||
| + | cd | ||
| + | mkdir .ssh && chmod 700 .ssh | ||
| + | touch .ssh/ | ||
| + | </ | ||
| + | |||
| + | 2. Genero claves en el cliente y las subo al servidor | ||
| + | |||
| + | < | ||
| + | ssh-keygen -t rsa | ||
| + | scp / | ||
| + | </ | ||
| + | |||
| + | 3. Volcar las claves: | ||
| + | |||
| + | < | ||
| + | sudo su git | ||
| + | cat / | ||
| + | </ | ||
| + | |||
| + | ===== Volver a un commit previo ===== | ||
| + | |||
| + | Escenario: | ||
| + | |||
| + | * Queremos volver a un commit previo | ||
| + | * Queremos hacer un nuevo commit indicando "se ha vuelto al commit XXXX" | ||
| + | |||
| + | 1. Identificar el commit ID al que queremos volver: | ||
| + | |||
| + | git log | ||
| + | |||
| + | En este ejemplo: | ||
| + | |||
| + | commit c501b1d989d780ab17412fc646b62bfe24aa24d5 (tag: v0.10.0) | ||
| + | |||
| + | 2. Volver a ese commit en la copia local: | ||
| + | |||
| + | git reset --hard c501b1d989d780ab17412fc646b62bfe24aa24d5 | ||
| + | |||
| + | 3. **TODO**: clarificar qué hace exactamente este paso | ||
| + | |||
| + | git reset --soft HEAD@{1} | ||
| + | |||
| + | 4. Hacer un nuevo commit | ||
| + | |||
| + | git commit -m " | ||
| + | |||
| + | 5. Subir los cambios al repositorio remoto | ||
| + | |||
| + | git push | ||
| + | |||
| + | ===== Comandos sueltos ===== | ||
| http:// | http:// | ||
| Line 41: | Line 168: | ||
| git push --tags origin | git push --tags origin | ||
| </ | </ | ||
| + | * Descargar un tag determinado: | ||
| + | < | ||
| + | git clone -b ' | ||
| + | </ | ||
| + | |||
| + | ===== Hooks ===== | ||
| + | |||
| + | ==== Desplegar el contenido de un repositorio tras recibir un commit ==== | ||
| + | |||
| + | 1. Crear el hook ' | ||
| + | |||
| + | sudo vim / | ||
| + | | ||
| + | Con el siguiente contenido: | ||
| + | |||
| + | < | ||
| + | #!/bin/sh | ||
| + | git --work-tree=/ | ||
| + | </ | ||
| + | |||
| + | chmod +x / | ||
| + | | ||
| + | 2. Hacer un commit | ||
| + | |||
| + | Resultado: el directorio "/ | ||
| + | |||
| + | ==== Enviar un correo tras recibir un commit ==== | ||
| + | |||
| + | 1. Crear el hook ' | ||
| + | |||
| + | sudo vim / | ||
| + | | ||
| + | Con el siguiente contenido: | ||
| + | |||
| + | < | ||
| + | #!/bin/bash | ||
| + | |||
| + | # Please adjust this setting | ||
| + | RECIPIENTS=" | ||
| + | GIT="/ | ||
| + | SENDMAIL="/ | ||
| + | export USER_EMAIL=$($GIT log -1 --format=format: | ||
| + | REPOSITORY=${PWD## | ||
| + | MAIL_CONTENT=`$GIT log --name-status HEAD^..HEAD` | ||
| + | SUBJECT=$USER_EMAIL" | ||
| + | |||
| + | $SENDMAIL " | ||
| + | subject: | ||
| + | from: | ||
| + | $MAIL_CONTENT | ||
| + | EOF | ||
| + | </ | ||
| + | |||
| + | chmod +x / | ||
| + | | ||
| + | 2. Hacer un commit | ||
| + | |||
| + | Resultado: el directorio "/ | ||
| + | |||
| + | ==== GITHUB ==== | ||
| + | Vamos a Settings "SSH and GPG keys" y añadimos la clave. | ||
| + | |||
| + | Creamos el repositorio en GITHUB. Mejor no inicializar con README.md Allí pone las instrucciones: | ||
| + | < | ||
| + | git init . | ||
| + | git add . | ||
| + | git commit -m " | ||
| + | git remote add origin git@github.com: | ||
| + | git push -u origin master | ||
| + | </ | ||
| + | |||
| + | ====== Deshacer un commit manteniendo cambios en local ====== | ||
| + | Si hacemos un commit antes de un pull y en el servidor hay cambios pero nuestro commit no afecta a esos cambios, para evitar conflictos, deshacemos el commit pero manteniendo los cambios en local: | ||
| + | git reset --soft HEAD^ | ||
| + | |||
| + | |||
informatica/git.1393425180.txt.gz · Last modified: (external edit)
