informatica:git
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
informatica:git [2013/12/30 07:29] – created javi | informatica:git [2019/12/30 19:07] – [Añadir rama branch] jose | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== git ===== | + | ====== git ====== |
+ | |||
+ | ===== 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: | ||
+ | / | ||
+ | |||
+ | 1. Create the git repository: | ||
+ | git init / | ||
+ | |||
+ | 2. Do the first commit | ||
+ | cd / | ||
+ | git add * | ||
+ | git commit -m " | ||
+ | |||
+ | 3. Create the " | ||
+ | git clone --bare / | ||
+ | |||
+ | 4. Move the directory to its final location using SSH | ||
+ | scp -rv / | ||
+ | |||
+ | ===== Subir un cambio ===== | ||
+ | |||
+ | 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 / | ||
+ | |||
+ | 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 / | ||
+ | </ | ||
+ | |||
+ | ===== Comandos sueltos | ||
http:// | http:// | ||
- | git remote update | + | |
+ | < | ||
+ | git remote update | ||
+ | </ | ||
+ | * Will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same. | ||
+ | < | ||
+ | git status -uno | ||
+ | </ | ||
+ | * Will show you the commits in all of the branches whose names end in master (eg master and origin/ | ||
+ | < | ||
+ | git show-branch *master | ||
+ | </ | ||
+ | * Subir tags a remoto | ||
+ | < | ||
+ | git push --tags origin | ||
+ | </ | ||
+ | * Descargar un tag determinado: | ||
+ | < | ||
+ | git clone -b ' | ||
+ | </ | ||
- | To bring your remote refs up to date: | + | ===== 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 / | ||
| | ||
- | Will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same. | + | 2. Hacer un commit |
- | | + | Resultado: el directorio "/ |
+ | |||
+ | ==== Enviar un correo tras recibir un commit ==== | ||
+ | |||
+ | 1. Crear el hook ' | ||
+ | |||
+ | sudo vim / | ||
| | ||
- | Will show you the commits in all of the branches whose names end in master | + | Con el siguiente contenido: |
+ | |||
+ | < | ||
+ | # | ||
+ | |||
+ | # 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 " | ||
+ | |||
+ | 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 push -u origin master | ||
+ | </ | ||
+ | |||
+ |
informatica/git.txt · Last modified: 2022/01/06 20:19 by jose