Share
Embed
Taller de Git HackLab Almeria 1/2
Taller de introduccion a Git/GitHub impartido en HackLabAlmeria
parte 1 de 2
Antonio Morales
September 15, 2017
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
88 slides
-
Control de versiones • Gestion de cambios en ficheros de
un proyecto. • Archivos en texto plano → codigo fuente. • Comprobar cambios realizados • Volver a estados anteriores. • Distintas personas trabajando en un mismo fichero. • Integrar cambios realizados por distintas personas. -
¿Que es Git ? • Sistema de control de versiones
distribuido • Gestion de ramas ligera • OpenSource -
Estados de un fichero • Sin seguimiento (Untracked) • Sin
cambios (Unmodified) • Modificado (Modified) • Listo para guardar (Staged) • Guardado (Commited) -
Instalar Git sudo apt-get install git Debian y derivados Fedora
yum install git-core (hasta Fedora 21) dnf install git (Fedora 22 y posteriores) Mac y Windows Descargar desde http://git-scm.org -
Iniciar un repositorio (init) amr@amr-C16B:~/Documentos$ mkdir tallerGit amr@amr-C16B:~/Documentos/tallerGit$ ll total
12 drwxrwxr-x 3 amr amr 4096 may 31 19:08 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ drwxrwxr-x 7 amr amr 4096 may 31 19:04 .git/ amr@amr-C16B:~/Documentos$ cd tallerGit/ amr@amr-C16B:~/Documentos/tallerGit$ git init Initialized empty Git repository in /home/amr/Documentos/tallerGit/.git/ -
Iniciar un repositorio (init) amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama
master Commit inicial nada que hacer (crear/copiar archivos y utilice «git add» para continuar) amr@amr-C16B:~/Documentos/tallerGit$ -
Crear ficheros amr@amr-C16B:~/Documentos/tallerGit$ touch readme.md amr@amr-C16B:~/Documentos/tallerGit$ ll total 12 drwxrwxr-x
3 amr amr 4096 may 31 19:12 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ drwxrwxr-x 7 amr amr 4096 may 31 19:12 .git/ -rw-rw-r-- 1 amr amr 0 may 31 19:12 readme.md -
Crear ficheros amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master Commit
inicial Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) readme.md no se ha agregado nada al commit pero existen archivos sin seguimiento (use «git add» para darle seguimiento) amr@amr-C16B:~/Documentos/tallerGit$ -
Añadir al versionado (add) amr@amr-C16B:~/Documentos/tallerGit$ git add readme.md amr@amr-C16B:~/Documentos/tallerGit$ git
status En la rama master Commit inicial Cambios para hacer commit: (use «git rm --cached <archivo>...» para sacar del stage) new file: readme.md amr@amr-C16B:~/Documentos/tallerGit$ -
Registrar cambios (commit) amr@amr-C16B:~/Documentos/tallerGit$ git commit -m "commit inicial" [master
(root-commit) 95f247b] commit inicial 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 readme.md amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master nothing to commit, working directory clean -
Comprobar historico (log) amr@amr-C16B:~/Documentos/tallerGit$ git log commit 95f247b24142f84ca03a699fc774fd60927039f8 Author: Antonio
Morales <[email protected]> Date: Wed May 31 19:19:37 2017 +0200 commit inicial amr@amr-C16B:~/Documentos/tallerGit$ -
Comprobar estado amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master Cambios
no preparados para el commit: (use «git add <archivo>...» para actualizar lo que se confirmará) (use «git checkout -- <archivo>...» para descartar cambios en el directorio de trabajo) modificado: readme.md Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) readme.md~ no hay cambios agregados al commit (use «git add» o «git commit -a») amr@amr-C16B:~/Documentos/tallerGit$ -
Ignorando ficheros (ignore) amr@amr-C16B:~/Documentos/tallerGit$ ll total 16 drwxrwxr-x 3 amr
amr 4096 may 31 19:30 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ drwxrwxr-x 8 amr amr 4096 may 31 19:31 .git/ -rw-rw-r-- 1 amr amr 13 may 31 19:30 readme.md -rw-rw-r-- 1 amr amr 0 may 31 19:23 readme.md~ amr@amr-C16B:~/Documentos/tallerGit$ amr@amr-C16B:~/Documentos/tallerGit$ gedit .gitignore amr@amr-C16B:~/Documentos/tallerGit$ ll total 16 drwxrwxr-x 3 amr amr 4096 may 31 19:30 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ drwxrwxr-x 8 amr amr 4096 may 31 19:31 .git/ -rw-rw-r-- 1 amr amr 13 may 31 19:30 readme.md -rw-rw-r-- 1 amr amr 0 may 31 19:23 readme.md~ amr@amr-C16B:~/Documentos/tallerGit$ Dentro del directorio del repositorio creamos el fichero .gitignore -
Ignorando ficheros (ignore) amr@amr-C16B:~/Documentos/tallerGit$ git add .gitignore amr@amr-C16B:~/Documentos/tallerGit$ git commit
-m "añadir ficheros ignorados" [master 3748642] añadir ficheros ignorados 1 file changed, 3 insertions(+) create mode 100644 .gitignore -
Ignorando ficheros (ignore) amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master
Cambios no preparados para el commit: (use «git add <archivo>...» para actualizar lo que se confirmará) (use «git checkout -- <archivo>...» para descartar cambios en el directorio de trabajo) modificado: readme.md no hay cambios agregados al commit (use «git add» o «git commit -a») -
Comprobar cambios (diff) amr@amr-C16B:~/Documentos/tallerGit$ git diff readme.md diff --git a/readme.md
b/readme.md index e69de29..4389cd0 100644 --- a/readme.md +++ b/readme.md @@ -0,0 +1 @@ +# Taller git -
Mas cambios (add + commit) amr@amr-C16B:~/Documentos/tallerGit$ git add . amr@amr-C16B:~/Documentos/tallerGit$
git commit -m "añadida cabecera" [master 9c78d33] añadida cabecera 1 file changed, 1 insertion(+) amr@amr-C16B:~/Documentos/tallerGit$ -
Comprobar historico (log) amr@amr-C16B:~/Documentos/tallerGit$ git log commit 9c78d33d2cb59f76fabe996e0f659be6408f5699 Author: Antonio
Morales <[email protected]> Date: Wed May 31 23:29:04 2017 +0200 añadida cabecera commit 3748642554e4dab6a1fee2ad0f328a2ccd14b6a1 Author: Antonio Morales <[email protected]> Date: Wed May 31 19:56:42 2017 +0200 añadir ficheros ignorados commit 95f247b24142f84ca03a699fc774fd60927039f8 Author: Antonio Morales <[email protected]> Date: Wed May 31 19:19:37 2017 +0200 commit inicial -
Deshaciendo cambios (reset) amr@amr-C16B:~/Documentos/tallerGit$ touch fichero.txt amr@amr-C16B:~/Documentos/tallerGit$ git add .
amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master Cambios para hacer commit: (use «git reset HEAD <archivo>...» para sacar del stage) new file: fichero.txt amr@amr-C16B:~/Documentos/tallerGit$ -
Deshaciendo cambios (reset) amr@amr-C16B:~/Documentos/tallerGit$ git reset HEAD fichero.txt amr@amr-C16B:~/Documentos/tallerGit$ git
status En la rama master Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) fichero.txt no se ha agregado nada al commit pero existen archivos sin seguimiento (use «git add» para darle seguimiento) amr@amr-C16B:~/Documentos/tallerGit$ -
Deshaciendo cambios (checkout) amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master
Cambios no preparados para el commit: (use «git add <archivo>...» para actualizar lo que se confirmará) (use «git checkout -- <archivo>...» para descartar cambios en el directorio de trabajo) modificado: readme.md Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) fichero.txt no hay cambios agregados al commit (use «git add» o «git commit -a») -
Deshaciendo cambios (checkout) amr@amr-C16B:~/Documentos/tallerGit$ git diff diff --git a/readme.md b/readme.md
index 4389cd0..9384c23 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,2 @@ # Taller git +este texto no esta bien amr@amr-C16B:~/Documentos/tallerGit$ -
Deshaciendo cambios (checkout) amr@amr-C16B:~/Documentos/tallerGit$ git checkout -- readme.md amr@amr-C16B:~/Documentos/tallerGit$ git
status En la rama master Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) fichero.txt no se ha agregado nada al commit pero existen archivos sin seguimiento (use «git add» para darle seguimiento) amr@amr-C16B:~/Documentos/tallerGit$ -
Deshaciendo cambios registrados amr@amr-C16B:~/Documentos/tallerGit$ git commit -am "registrar cambios erroneos"
[master 1445343] registrar cambios erroneos 1 file changed, 1 insertion(+) amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) fichero.txt no se ha agregado nada al commit pero existen archivos sin seguimiento (use «git add» para darle seguimiento) amr@amr-C16B:~/Documentos/tallerGit$ -
Deshaciendo cambios registrados amr@amr-C16B:~/Documentos/tallerGit$ git log --decorate commit 14c01d888f3298706c3ab259852613da0ef2ae34 (HEAD,
master) Author: Antonio Morales <[email protected]> Date: Mon Aug 28 00:01:54 2017 +0200 registrar cambios erroneos commit b615619386a3c2ea6173d20cff778335a5d437bc Author: Antonio Morales <[email protected]> Date: Sun Aug 27 18:15:46 2017 +0200 añadida cabecera commit 16d99d6a0a9fb706a30eb15468936c21643b8c57 Author: Antonio Morales <[email protected]> Date: Sun Aug 27 18:13:46 2017 +0200 añadir ficheros ignorados -
Deshaciendo cambios registrados amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master
Cambios no preparados para el commit: (use «git add <archivo>...» para actualizar lo que se confirmará) (use «git checkout -- <archivo>...» para descartar cambios en el directorio de trabajo) modificado: readme.md Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) fichero.txt no hay cambios agregados al commit (use «git add» o «git commit -a») amr@amr-C16B:~/Documentos/tallerGit$ git reset HEAD~ -
Deshaciendo cambios registrados amr@amr-C16B:~/Documentos/tallerGit$ git log --oneline --decorate b615619 (HEAD,
master) añadida cabecera 16d99d6 añadir ficheros ignorados 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ git checkout -- readme.md amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master Archivos sin seguimiento: (use «git add <archivo>...» para incluir en lo que se ha de confirmar) fichero.txt no se ha agregado nada al commit pero existen archivos sin seguimiento (use «git add» para darle seguimiento) -
Borrando cosas (rm) amr@amr-C16B:~/Documentos/tallerGit$ rm fichero.txt amr@amr-C16B:~/Documentos/tallerGit$ ll total 24
drwxrwxr-x 3 amr amr 4096 jun 1 18:48 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ -rw-rw-r-- 1 amr amr 0 may 31 23:44 fichero.txt drwxrwxr-x 8 amr amr 4096 jun 1 18:48 .git/ -rw-rw-r-- 1 amr amr 13 may 31 19:55 .gitignore -rw-rw-r-- 1 amr amr 13 jun 1 18:48 readme.md -rw-rw-r-- 1 amr amr 13 jun 1 18:41 readme.md~ amr@amr-C16B:~/Documentos/tallerGit$ -
Borrando cosas (rm) amr@amr-C16B:~/Documentos/tallerGit$ ll total 24 drwxrwxr-x 3 amr
amr 4096 jun 1 18:52 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ drwxrwxr-x 8 amr amr 4096 jun 1 18:58 .git/ -rw-rw-r-- 1 amr amr 13 may 31 19:55 .gitignore -rw-rw-r-- 1 amr amr 13 jun 1 18:48 readme.md -rw-rw-r-- 1 amr amr 13 jun 1 18:41 readme.md~ amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master nothing to commit, working directory clean amr@amr-C16B:~/Documentos/tallerGit$ -
Borrando cosas (rm) amr@amr-C16B:~/Documentos/tallerGit$ rm readme.md amr@amr-C16B:~/Documentos/tallerGit$ git status En
la rama master Cambios no preparados para el commit: (use «git add/rm <archivo>...» para actualizar lo que se confirmará) (use «git checkout -- <archivo>...» para descartar cambios en el directorio de trabajo) deleted: readme.md no hay cambios agregados al commit (use «git add» o «git commit -a») amr@amr-C16B:~/Documentos/tallerGit$ -
Borrando cosas (rm) amr@amr-C16B:~/Documentos/tallerGit$ git checkout -- readme.md amr@amr-C16B:~/Documentos/tallerGit$ git
status En la rama master nothing to commit, working directory clean amr@amr-C16B:~/Documentos/tallerGit$ ll total 24 drwxrwxr-x 3 amr amr 4096 jun 1 18:52 ./ drwxr-xr-x 24 amr amr 4096 may 31 18:48 ../ drwxrwxr-x 8 amr amr 4096 jun 1 18:58 .git/ -rw-rw-r-- 1 amr amr 13 may 31 19:55 .gitignore -rw-rw-r-- 1 amr amr 13 jun 1 18:48 readme.md -rw-rw-r-- 1 amr amr 13 jun 1 18:41 readme.md~ -
Borrando cosas (rm) amr@amr-C16B:~/Documentos/tallerGit$ git rm readme.md rm 'readme.md' amr@amr-C16B:~/Documentos/tallerGit$
git status En la rama master Cambios para hacer commit: (use «git reset HEAD <archivo>...» para sacar del stage) deleted: readme.md amr@amr-C16B:~/Documentos/tallerGit$ -
Borrando cosas (rm) amr@amr-C16B:~/Documentos/tallerGit$ git commit -m "se elimina fichero
readme" amr@amr-C16B:~/Documentos/tallerGit$ git log --decorate --oneline --graph * a9ac4be (HEAD, master) se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ -
Trabajando con Ramas Master Dev F1 F2 Bug1 V0.1.0 V0.1.1
V0.2.0 V0.3.0 -
Creando ramas (branch) amr@amr-C16B:~/Documentos/tallerGit$ git branch dev amr@amr-C16B:~/Documentos/tallerGit$ git branch
dev * master amr@amr-C16B:~/Documentos/tallerGit$ git checkout dev Switched to branch 'dev' amr@amr-C16B:~/Documentos/tallerGit$ git branch * dev master amr@amr-C16B:~/Documentos/tallerGit$ git branch * master -
Creando ramas (branch) amr@amr-C16B:~/Documentos/tallerGit$ git log --graph --oneline --decorate *
a9ac4be (HEAD, master, dev) se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial -
Añadiendo cambios a las ramas amr@amr-C16B:~/Documentos/tallerGit$ git add readme.md amr@amr-C16B:~/Documentos/tallerGit$
git commit -m "se añade readme de nuevo" [dev 6724ac6] se añade readme de nuevo 1 file changed, 3 insertions(+) create mode 100644 readme.md amr@amr-C16B:~/Documentos/tallerGit$ git log --graph --oneline --decorate * 6724ac6 (HEAD, dev) se añade readme de nuevo * a9ac4be (master) se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial -
Cambiando entre ramas (checkout) amr@amr-C16B:~/Documentos/tallerGit$ git checkout master Switched to
branch 'master' amr@amr-C16B:~/Documentos/tallerGit$ ls -a . .. .git .gitignore readme.md readme.md~ amr@amr-C16B:~/Documentos/tallerGit$ git log --graph --oneline --decorate * a9ac4be (HEAD, master) se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ ls -a . .. .git .gitignore readme.md~ -
¿Dónde estan mis archivos? amr@amr-C16B:~/Documentos/tallerGit$ git log dev --graph --oneline
--decorate --branches * 6724ac6 (dev) se añade readme de nuevo * a9ac4be (HEAD, master) se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ git log ^master dev --graph --oneline --decorate * 6724ac6 (dev) se añade readme de nuevo -
Fusionando ramas FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git merge dev Updating a9ac4be..6724ac6
Fast-forward readme.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 readme.md amr@amr-C16B:~/Documentos/tallerGit$ git log --graph --oneline --decorate * 6724ac6 (HEAD, master, dev) se añade readme de nuevo * a9ac4be se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial -
¿Dónde estan mis archivos? amr@amr-C16B:~/Documentos/tallerGit$ git log dev --graph --oneline
--decorate --branches * 6724ac6 (dev) se añade readme de nuevo * a9ac4be (HEAD, master) se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ git log ^master dev --graph --oneline --decorate * 6724ac6 (dev) se añade readme de nuevo -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git checkout -b F1
Switched to a new branch 'F1' amr@amr-C16B:~/Documentos/tallerGit$ gedit readme.md -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git commit -am "añadida
funcionalidad F1" [F1 918b6ae] añadida funcionalidad F1 1 file changed, 1 insertion(+) amr@amr-C16B:~/Documentos/tallerGit$ git checkout dev Switched to branch 'dev' amr@amr-C16B:~/Documentos/tallerGit$ git merge F1 Updating 6724ac6..918b6ae Fast-forward readme.md | 1 + 1 file changed, 1 insertion(+) -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git log --graph --oneline
--decorate * 918b6ae (HEAD, dev, F1) añadida funcionalidad F1 * 6724ac6 (master) se añade readme de nuevo * a9ac4be se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ git checkout master Switched to branch 'master' amr@amr-C16B:~/Documentos/tallerGit$ gedit readme.md -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git commit -am "se
corrige bug gordo" [master 2068b5a] se corrige bug gordo 1 file changed, 1 insertion(+), 1 deletion(-) -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git log --oneline --decorate
--graph --branches * 2068b5a (HEAD, master) se corrige bug gordo | * 918b6ae (dev, F1) añadida funcionalidad F1 |/ * 6724ac6 se añade readme de nuevo * a9ac4be se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git merge dev Automezclado
readme.md CONFLICTO(contenido): conflicto de fusión en readme.md Automatic merge failed; fix conflicts and then commit the result. amr@amr-C16B:~/Documentos/tallerGit$ git status En la rama master Tiene rutas sin fusionar. (solucione los conflictos y ejecute «git commit») Rutas no combinadas: (use «git add <archivo>...» para marcar resolución) modificado por ambos:readme.md no hay cambios agregados al commit (use «git add» o «git commit -a») -
Fusionando ramas no FF (merge) amr@amr-C16B:~/Documentos/tallerGit$ git log --oneline --decorate
--graph * e474df1 (HEAD, master) fusionar rama dev |\ | * 918b6ae (dev, F1) añadida funcionalidad F1 * | 2068b5a se corrige bug gordo |/ * 6724ac6 se añade readme de nuevo * a9ac4be se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ git commit -am "fusionar rama dev" [master e474df1] fusionar rama dev -
Borrando ramas amr@amr-C16B:~/Documentos/tallerGit$ git log --oneline --decorate --graph * e474df1
(HEAD, master) fusionar rama dev |\ | * 918b6ae (dev) añadida funcionalidad F1 * | 2068b5a se corrige bug gordo |/ * 6724ac6 se añade readme de nuevo * a9ac4be se elimina fichero readme * b615619 añadida cabecera * 16d99d6 añadir ficheros ignorados * 95f247b commit inicial amr@amr-C16B:~/Documentos/tallerGit$ git branch -d F1 Eliminada la rama F1 (era 918b6ae)