Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Control de versiones distribuido con GIT

Control de versiones distribuido con GIT

Slides from my talk in GUL-UC3M '2009 (and some other events afterwards)

Sergio Gil

April 09, 2012
Tweet

More Decks by Sergio Gil

Other Decks in Programming

Transcript

  1. Configuración $ git config --global user.name "Fulano Mengánez" $ git

    config --global user.email [email protected] $ git config --global color.branch auto $ git config --global color.diff auto $ git config --global color.interactive auto $ git config --global color.status auto
  2. Crear un repositorio $ mkdir wadus $ cd wadus/ $

    git init Initialized empty Git repository in /Users/sergio/Code/wadus/.git/
  3. Comitear $ git commit -m "Initial commit" [master (root-commit) 66ff7bd]

    Initial commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 wadus.rb
  4. Ver diferencias $ git diff diff --git a/wadus.rb b/wadus.rb index

    94b29af..2a5c7b6 100644 --- a/wadus.rb +++ b/wadus.rb @@ -1 +1,2 @@ puts "this is wadus.rb" +puts "yeah, welcome to wadus.rb"
  5. Comitear otra vez $ git status # On branch master

    # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working dire # # modified: wadus.rb # no changes added to commit (use "git add" and/or "git commit -a")
  6. Comitear otra vez $ git add wadus.rb $ git commit

    -m "Added one more message" [master 77517a3] Added one more message 1 files changed, 1 insertions(+), 0 deletions(-)
  7. Es necesario añadir los cambios que queremos comitear aunque el

    archivo ya estuviera bajo control de versiones
  8. Es necesario añadir los cambios que queremos comitear aunque el

    archivo ya estuviera bajo control de versiones O usar -a
  9. Comitear otra vez $ git commit -a -m "Added one

    more message" [master d1326c7] Added one more message 1 files changed, 1 insertions(+), 0 deletions(-)
  10. Renombrar/mover archivos $ mkdir src $ git mv wadus.rb src/

    $ git commit -m "Moved code into src"
  11. Renombrar/mover archivos $ mkdir src $ git mv wadus.rb src/

    $ git commit -m "Moved code into src" [master d49c8e0] Moved code into src 1 files changed, 0 insertions(+), 0 deletions(-) rename wadus.rb => src/wadus.rb (100%)
  12. $ git log commit d1326c7c4d4130730f2e37783790926dec7115dc Author: Sergio Gil <[email protected]> Date:

    Tue Nov 3 01:09:35 2009 +0100 Added one more message commit 84eaf2150285685e33e32e2595e1fd1beae59327 Author: Sergio Gil <[email protected]> Date: Tue Nov 3 00:59:18 2009 +0100 Initial commit Consultar el log
  13. git log •multitud de opciones de formato •multitud de formas

    de especificar rangos de revisiones •mola aprender algunas porque valen también para git diff
  14. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21
  15. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21 $ git log d1326c7..HEAD
  16. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21 $ git log d1326c7..HEAD $ git log --since="2 days"
  17. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21 $ git log d1326c7..HEAD $ git log --since="2 days" $ git log HEAD~
  18. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21 $ git log d1326c7..HEAD $ git log --since="2 days" $ git log HEAD~ $ git log HEAD^2
  19. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21 $ git log d1326c7..HEAD $ git log --since="2 days" $ git log HEAD~ $ git log HEAD^2 $ git diff 1.0~..1.0
  20. Especificar rangos de revisiones $ git log 1.0 $ git

    log d1326c7 $ git log d1326c7..84eaf21 $ git log d1326c7..HEAD $ git log --since="2 days" $ git log HEAD~ $ git log HEAD^2 $ git diff 1.0~..1.0 $ git diff HEAD@{24 hours ago}
  21. Volver a una revisión $ git checkout 1.0 Note: moving

    to '1.0' which isn't a local branch If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new_branch_name> HEAD is now at d1326c7... Added one more message
  22. $ git blame src/wadus.rb ^84eaf21 wadus.rb (Sergio Gil 2009-11-03 00:59:18

    +0100 1) puts "this is wadus.rb" d1326c7c wadus.rb (Sergio Gil 2009-11-03 01:09:35 +0100 2) puts "yeah, welcome to wadus.rb" Buscar culpables =;-)
  23. $ git checkout -b experimental Switched to a new branch

    'experimental' Crear una rama y cambiar a ella (atajo)
  24. $ git checkout -b experimental Switched to a new branch

    'experimental' $ git branch Crear una rama y cambiar a ella (atajo)
  25. $ git checkout -b experimental Switched to a new branch

    'experimental' $ git branch * experimental master Crear una rama y cambiar a ella (atajo)
  26. $ git merge experimental Updating d49c8e0..6dd50c5 Fast forward src/wadus.rb |

    5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) Mergear ramas
  27. $ git merge experimental Auto-merging src/wadus.rb Merge made by recursive.

    src/wadus.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) Mergear de nuevo
  28. $ git merge experimental Auto-merging src/wadus.rb CONFLICT (content): Merge conflict

    in src/wadus.rb Automatic merge failed; fix conflicts and then commit the result. Mergear de nuevo
  29. $ git add src/wadus.rb $ git commit [master 8dc69ab] Merge

    branch 'experimental' Resolver un conflicto
  30. $ git checkout feature1 Switched to branch 'feature1' $ git

    rebase master First, rewinding head to replay your work on top of it... Applying: New feature rebase + merge
  31. $ git checkout master Switched to branch 'master' $ git

    merge feature1 Updating b70bad0..e5a1424 Fast forward src/wadus.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) rebase + merge
  32. Ese es el ejemplo más básico, pero git rebase permite

    hacer todo tipo de cambios en la historia
  33. Al ser todas las operaciones en local, todo lo que

    ya hemos hecho es control distribuido per se
  34. $ git remote $ cd .. $ git clone wadus/

    wadus2 Initialized empty Git repository in /Users/sergio/Code/wadus2/.git/ remote + clone
  35. $ git remote $ cd .. $ git clone wadus/

    wadus2 Initialized empty Git repository in /Users/sergio/Code/wadus2/.git/ $ cd wadus2 remote + clone
  36. $ git remote $ cd .. $ git clone wadus/

    wadus2 Initialized empty Git repository in /Users/sergio/Code/wadus2/.git/ $ cd wadus2 $ git remote remote + clone
  37. $ git remote $ cd .. $ git clone wadus/

    wadus2 Initialized empty Git repository in /Users/sergio/Code/wadus2/.git/ $ cd wadus2 $ git remote origin remote + clone
  38. $ git fetch origin remote: Counting objects: 7, done. remote:

    Compressing objects: 100% (2/2), done. remote: Total 4 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. From /Users/sergio/Code/wadus e5a1424..13fab0a master -> origin/master [master d1326c7] Added one more message 1 files changed, 1 insertions(+), 0 deletions(-) fetch
  39. $ git merge origin/master Updating e5a1424..13fab0a Fast forward src/wadus.rb |

    1 + 1 files changed, 1 insertions(+), 0 deletions(-) Mergear rama remota
  40. $ git pull origin master From ../wadus * branch master

    -> FETCH_HEAD Updating e5a1424..13fab0a Fast forward src/wadus.rb | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) pull = fetch + merge
  41. $ cd ../wadus $ git remote $ git remote add

    developer1 ../wadus2 Añadir repositorios remotos
  42. $ cd ../wadus $ git remote $ git remote add

    developer1 ../wadus2 $ git checkout -b integration Añadir repositorios remotos
  43. $ cd ../wadus $ git remote $ git remote add

    developer1 ../wadus2 $ git checkout -b integration Switched to a new branch 'integration' Añadir repositorios remotos
  44. $ cd ../wadus $ git remote $ git remote add

    developer1 ../wadus2 $ git checkout -b integration Switched to a new branch 'integration' $ git pull developer1 master Añadir repositorios remotos
  45. $ cd ../wadus $ git remote $ git remote add

    developer1 ../wadus2 $ git checkout -b integration Switched to a new branch 'integration' $ git pull developer1 master remote: Counting objects: 7, done. remote: Compressing objects: 100% (2/2), done. remote: Total 4 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. From ../wadus2 * branch master -> FETCH_HEAD Updating 13fab0a..f602261 Fast forward src/wadus.rb | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) Añadir repositorios remotos
  46. $ git push origin master Counting objects: 7, done. Delta

    compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (4/4), 339 bytes, done. Total 4 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (4/4), done. To ../wadus/ 13fab0a..f602261 master -> master push
  47. Reescribir la historia con git rebase -i Ejemplo de workflow

    (resolver un bug) git add --patch Búsqueda de bugs con git-bisect