SlideShare a Scribd company logo
1 of 39
Download to read offline
Git é seu amigo



                               Celestino Gomes




Saturday, September 12, 2009                     1
O quê?

       • Criado em 2005 por Linus Torvalds

             • Necessidade, linux-kernel-devs


       • Originalmente, era um engine para VCS

       • Fluxo de trabalho distribuído

       • Prevenção de corrupção acidental

       • Alta performance




Saturday, September 12, 2009                     2
Características básicas

       • Controle de versão distribuido (DVCS)

       • Gerenciamento de conteúdo e não arquivos

       • Branches como unidade de trabalho

       • SHA1 para associação e verificação

       • Staging index

       • Não é o subversion



Saturday, September 12, 2009                        3
Como funciona?




Saturday, September 12, 2009   4
Diretório .git

       • Diretório .git na raíz de cada projeto

       • Arquivos de configuração (.git/config)

       • Index (.git/index)

       • Hooks (.git/hooks)

       • Object Database (.git/objects)

       • References (.git/refs)



Saturday, September 12, 2009                      5
Object Database
     • Quatro tipos de objetos:

          • Blob, Tree, Commit e Tag


     • Todos registrados/gravados da mesma maneira




Saturday, September 12, 2009                         6
Object Database - Loose format



                   conteudo


                   header + conteudo


                    “2e6f9b0d5885b6010f9167787445617f553a735f”


                   zlib(header + conteudo)



                   .git/objects/2e/6f9b0d5885b6010f9167787445617f553a735f



Saturday, September 12, 2009                                                7
Object Database - Packed format

                   .git/objects/2e/6f9b0d5885b6010f9167787445617f553a735f

                   .git/objects/0b/772ec8eb9ae8952c3c1e56a9ffbe49385cc83a

                   .git/objects/72/16b02627bc3d6ef57008f7ff67f0f8f13f488e



                                                              git-gc



          .git/objects/pack/pack-0bc9a42eb66d7ae36bf44af8ff5a3888e8a02d12.idx

         .git/objects/pack/pack-0bc9a42eb66d7ae36bf44af8ff5a3888e8a02d12.pack




Saturday, September 12, 2009                                                                                                            8
Digamos que os objetos listados referenciem o mesmo arquivo, com conjuntos pequenos de diferenças geradas ao longo do tempo. Usar uma
ferramenta de manutenção (git-gc, por exemplo) vai compactar os objetos e armazená-los em ‘/pack’.
Object Database - Blob

                                        Rakefile   blob: 2e6f9b



                               active_content.rb   blob: 7034fe



                          active_content_spec.rb   blob: a738fc




Saturday, September 12, 2009                                      9
Object Database - Tree

                                              /    tree: 1fba94



                                        Rakefile          blob: 2e6f9b



                                            /lib          tree: 3ef95a



                               active_content.rb                  blob: 7034fe



                                          /spec           tree: 34ba74



                  active_content_spec.rb                          blob: a738fc




Saturday, September 12, 2009                                                     10
Object Database - Commit

                                                   commit: 8d1ab4


                                              /     tree: 1fba94



                                        Rakefile    blob: 2e6f9b



                                            /lib    tree: 3ef95a



                               active_content.rb    blob: 7034fe



                                          /spec     tree: 34ba74



                  active_content_spec.rb            blob: a738fc




Saturday, September 12, 2009                                        11
Object Database - Commit

                                          commit: 8d1ab4   commit: 61db26


                                     /     tree: 1fba94     tree: 1fba94



                               Rakefile    blob: 2e6f9b     blob: 41d300



                                   /lib    tree: 3ef95a     tree: 3ef95a



                    active_content.rb      blob: 7034fe     blob: 7034fe



                                 /spec     tree: 34ba74     tree: 34ba74



       active_content_spec.rb              blob: a738fc     blob: 2a03fb




Saturday, September 12, 2009                                                12
Object Database - Tag

                                                    tag: 6ee1f2


                                                   commit: 8d1ab4


                                              /     tree: 1fba94


                                        Rakefile    blob: 2e6f9b


                                            /lib    tree: 3ef95a


                               active_content.rb    blob: 7034fe



                                          /spec     tree: 34ba74


                  active_content_spec.rb            blob: a738fc




Saturday, September 12, 2009                                        13
Object Database - Resumindo




Saturday, September 12, 2009         14
Object Database - Resumo

       • Blob é o menor objeto do git

       • Tree contém Trees e Blobs

       • Commit contém Commits, Trees e Blobs

       • Tags contém/apontam um Commit




Saturday, September 12, 2009                    15
References

                   .git/refs/heads/master                     master                      HEAD



                                                         commit: 8d1ab4


                                              /           tree: 1fba94


                                Rakefile                  blob: 2e6f9b


                                        /lib              tree: 3ef95a


                   active_content.rb                      blob: 7034fe



                                      /spec               tree: 34ba74


       active_content_spec.rb                             blob: a738fc




Saturday, September 12, 2009                                                                                                             16
Um branch é um ponteiro para um commit. Quando se avança um branch adicionando commits, o que está acontecendo, por baixo dos panos, é
mudar o ponteiro do branch para um novo commit.
Staging Index


                                 lib.rb      Untracked

                                   $ git add lib.rb


                                 lib.rb          Staged

                               $ git commit -m “lib.rb”


                                 lib.rb      Commited


Saturday, September 12, 2009                              17
Flow básico




Saturday, September 12, 2009   18
Criação de repositórios

       Criando um novo repositório

          $ rails my_blog
          ...
          $ cd my_blog
          $ git init
          $ git add .
          $ git commit -m “Initial commit”

      Criando um repositório a partir de um outro

          $ git clone git://github.com/tinogomes/my_blog_app_with_bug.git
          $ cd my_blog_app_with_bug
          $ git branch
          master



Saturday, September 12, 2009                                                19
Trabalhando em um branch remoto


            $ cd my_blog_app_with_bug
            $ git checkout -b refactoring origin/refactoring
            ... após modificações
            $ echo tmp > .gitignore
            $ git add .
            $ git commit -m “outras modificacoes”
            $ git pull
            $ git push origin refactoring




Saturday, September 12, 2009                                   20
Indo além do flow básico




Saturday, September 12, 2009     21
Adicionando arquivos



                                    $ git add <dir>


                               $ git add <dir>/<arquivo>



                                   $ git add *.rb



                                $ git add . (cuidado)




Saturday, September 12, 2009                               22
Trabalhando com branch local

          $ cd my_blog_app_with_bug
          $ git branch meu_branch_local
          ...
          $ git checkout master
          $ git pull . master
          $ git push origim master



          $ git branch -d meu_branch_local




Saturday, September 12, 2009                 23
Navegando pelo histórico

         $ git log --stat

         commit 7f5a85113381e8c0d16e4679c4e5a81a4eb000b8
         Author: Celestino Gomes <celestino@HDU15121-ADIGITAL.local>
         Date:   Sat Sep 12 02:22:52 2009 -0300

                Initial commit



          README                                     | 243 ++
          Rakefile                                   |   10 +
          app/controllers/application_controller.rb |    10 +
          app/helpers/application_helper.rb          |    3 +
          config/boot.rb                             | 110 +
         ...
          test/performance/browsing_test.rb          |    9 +
          test/test_helper.rb                        |   38 +
          41 files changed, 8452 insertions(+), 0 deletions(-)




Saturday, September 12, 2009                                           24
Navegando pelo histórico
         $ git log -p --no-merges

         commit 7f5a85113381e8c0d16e4679c4e5a81a4eb000b8
         Author: Celestino Gomes <celestino@HDU15121-ADIGITAL.local>
         Date:   Sat Sep 12 02:22:52 2009 -0300

                Initial commit

         diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb
         new file mode 100644
         index 0000000..4b60558
         --- /dev/null
         +++ b/test/performance/browsing_test.rb
         @@ -0,0 +1,9 @@
         +require 'test_helper'
         +require 'performance_test_help'
         +
         +# Profiling results for each test method are written to tmp/performance.
         +class BrowsingTest < ActionController::PerformanceTest
         + def test_homepage
         +    get '/'
         + end
         +end


Saturday, September 12, 2009                                                                  25
Navegando pelo histórico
   $ git log --pretty=oneline

   7f5a85113381e8c0d16e4679c4e5a81a4eb000b8 Initial commit

   $ git blame app/helpers/application_helper.rb

   ^7f5a851 (Celestino Gomes 2009-09-12 02:22:52 -0300 1) module ApplicationHelper
   ^7f5a851 (Celestino Gomes 2009-09-12 02:22:52 -0300 2) end




Saturday, September 12, 2009                                                         26
Manipulando o índice

       Remove do stage index

                  $ git reset [<commit>]

       Limpa os arquivos, inclusive os unstagged

                  $ git reset --hard [<commit>]
       Coloca os arquivos de volta para o stage index

                  $ git reset --soft [<commit>]

       Permite alterar o último commit

                  $ git commit --amend




Saturday, September 12, 2009                            27

<commit> - default HEAD
A diferença entre merge e rebase


                               master   sprint_branch



                                C1



                                C2          C4



                                C3          C5




Saturday, September 12, 2009                            28
A diferença entre merge e rebase

                       master      sprint_branch



                         C1
                                                   $ git checkout master
                                                   $ git pull . sprint_branch
                         C2            C4
                                                                 ou

                                                   $ git checkout master
                         C3            C5          $ git fetch
                                                   $ git merge sprint_branch


                         C6     merge commit




Saturday, September 12, 2009                                                    29
A diferença entre merge e rebase

                       master



                         C1
                                      $ git checkout master
                                      $ git pull --rebase . sprint_branch
                         C2     C4
                                                       ou

                                      $ git checkout master
                         C3     C5    $ git fetch
                                      $ git rebase sprint_branch


                        C4’     C5’




Saturday, September 12, 2009                                                30
Usando o stash


                                      $ git stash


                                   $ git stash list


                               $ git stash show stash@{0}


                                   $ git stash apply


                               $ git stash drop stash@{0}




Saturday, September 12, 2009                                31
Revertendo commits


                                $ git revert <commit_hash>


                               $ git revert -n <commit_hash>




Saturday, September 12, 2009                                   32

-n para deixar a reversão no index
Buscando por bugs


                                     $ git bisect start [<bad> [<good>]]


                                         $ git bisect good | bad [<rev>]


                                     $ git bisect skip [(<rev>|<range>)]


                                                       $ git bisect reset


                                         $ git bisect run <cmd | script>




Saturday, September 12, 2009                                                                                                                        33
1) Primeiro é necessário identificar pontos (commits) bons e ruins para começar a caça. Usar $ git log
2) $ git bisect run my_script - Note that the "run" script (my_script in the above example) should exit with code 0 in case the current source code is
good. Exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad.
Limpando a sujeira do dia-a-dia

       Remover arquivos/diretórios não trackeados
                    $ git clean -d -f



       Remover um branch remoto

                     $ git push origin :<branch_remoto>


       Limpar todo o stash

                    $ git stash clear




Saturday, September 12, 2009                                                                                                          34
clean para remover arquivos/diretórios não trackeados, push origin :<branch> limpa branches remotos, stash para limpar todo o stash
Funciona no Windows?

       • Somente através do cygwin ou msysGit




Saturday, September 12, 2009                    35
Referências

       • http://git.or.cz/gitwiki/GitDocumentation

       • http://www.kernel.org/pub/software/scm/git/docs/

       • http://blog.tinogomes.com/2008/05/11/instalando-e-usando-git-
         no-windows-xp/

       • http://github.com




Saturday, September 12, 2009                                             36
Perguntas




Saturday, September 12, 2009   37
Mais sobre mim




       • http://blog.tinogomes.com




Saturday, September 12, 2009         38
Obrigado!




Saturday, September 12, 2009   39

More Related Content

Similar to Git E Seu Amigo

Gitting It Under (Version) Control
Gitting It Under (Version) ControlGitting It Under (Version) Control
Gitting It Under (Version) Control
mobiledevnj
 
浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編 浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編
Masakuni Kato
 
HOW TO BUILD GEMS #shibuyarb
HOW TO BUILD GEMS #shibuyarbHOW TO BUILD GEMS #shibuyarb
HOW TO BUILD GEMS #shibuyarb
SATOSHI TAGOMORI
 
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
JAX London
 

Similar to Git E Seu Amigo (20)

Your first rails app - 2
 Your first rails app - 2 Your first rails app - 2
Your first rails app - 2
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous Task
 
App Lego
App LegoApp Lego
App Lego
 
The Future of library dependency manageement of Ruby
The Future of library dependency manageement of RubyThe Future of library dependency manageement of Ruby
The Future of library dependency manageement of Ruby
 
Gitting It Under (Version) Control
Gitting It Under (Version) ControlGitting It Under (Version) Control
Gitting It Under (Version) Control
 
Barcamp PT
Barcamp PTBarcamp PT
Barcamp PT
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
 
Rails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_manyRails ORM De-mystifying Active Record has_many
Rails ORM De-mystifying Active Record has_many
 
浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編 浜松Rails3道場 其の弐 Model編
浜松Rails3道場 其の弐 Model編
 
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OOVirtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
Virtuoso RDF Triple Store Analysis Benchmark & mapping tools RDF / OO
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflow
 
HOW TO BUILD GEMS #shibuyarb
HOW TO BUILD GEMS #shibuyarbHOW TO BUILD GEMS #shibuyarb
HOW TO BUILD GEMS #shibuyarb
 
Webinar - Approaching 1 billion documents with MongoDB
Webinar - Approaching 1 billion documents with MongoDBWebinar - Approaching 1 billion documents with MongoDB
Webinar - Approaching 1 billion documents with MongoDB
 
Coding For Config: Install Profile Development Using Features
Coding For Config: Install Profile Development Using FeaturesCoding For Config: Install Profile Development Using Features
Coding For Config: Install Profile Development Using Features
 
OSMC 2008 | A large scale distributed Nagios installation for T-Systems Enter...
OSMC 2008 | A large scale distributed Nagios installation for T-Systems Enter...OSMC 2008 | A large scale distributed Nagios installation for T-Systems Enter...
OSMC 2008 | A large scale distributed Nagios installation for T-Systems Enter...
 
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
Gems on Ruby
Gems on RubyGems on Ruby
Gems on Ruby
 
Rails 3 : Cool New Things
Rails 3 : Cool New ThingsRails 3 : Cool New Things
Rails 3 : Cool New Things
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Git E Seu Amigo

  • 1. Git é seu amigo Celestino Gomes Saturday, September 12, 2009 1
  • 2. O quê? • Criado em 2005 por Linus Torvalds • Necessidade, linux-kernel-devs • Originalmente, era um engine para VCS • Fluxo de trabalho distribuído • Prevenção de corrupção acidental • Alta performance Saturday, September 12, 2009 2
  • 3. Características básicas • Controle de versão distribuido (DVCS) • Gerenciamento de conteúdo e não arquivos • Branches como unidade de trabalho • SHA1 para associação e verificação • Staging index • Não é o subversion Saturday, September 12, 2009 3
  • 5. Diretório .git • Diretório .git na raíz de cada projeto • Arquivos de configuração (.git/config) • Index (.git/index) • Hooks (.git/hooks) • Object Database (.git/objects) • References (.git/refs) Saturday, September 12, 2009 5
  • 6. Object Database • Quatro tipos de objetos: • Blob, Tree, Commit e Tag • Todos registrados/gravados da mesma maneira Saturday, September 12, 2009 6
  • 7. Object Database - Loose format conteudo header + conteudo “2e6f9b0d5885b6010f9167787445617f553a735f” zlib(header + conteudo) .git/objects/2e/6f9b0d5885b6010f9167787445617f553a735f Saturday, September 12, 2009 7
  • 8. Object Database - Packed format .git/objects/2e/6f9b0d5885b6010f9167787445617f553a735f .git/objects/0b/772ec8eb9ae8952c3c1e56a9ffbe49385cc83a .git/objects/72/16b02627bc3d6ef57008f7ff67f0f8f13f488e git-gc .git/objects/pack/pack-0bc9a42eb66d7ae36bf44af8ff5a3888e8a02d12.idx .git/objects/pack/pack-0bc9a42eb66d7ae36bf44af8ff5a3888e8a02d12.pack Saturday, September 12, 2009 8 Digamos que os objetos listados referenciem o mesmo arquivo, com conjuntos pequenos de diferenças geradas ao longo do tempo. Usar uma ferramenta de manutenção (git-gc, por exemplo) vai compactar os objetos e armazená-los em ‘/pack’.
  • 9. Object Database - Blob Rakefile blob: 2e6f9b active_content.rb blob: 7034fe active_content_spec.rb blob: a738fc Saturday, September 12, 2009 9
  • 10. Object Database - Tree / tree: 1fba94 Rakefile blob: 2e6f9b /lib tree: 3ef95a active_content.rb blob: 7034fe /spec tree: 34ba74 active_content_spec.rb blob: a738fc Saturday, September 12, 2009 10
  • 11. Object Database - Commit commit: 8d1ab4 / tree: 1fba94 Rakefile blob: 2e6f9b /lib tree: 3ef95a active_content.rb blob: 7034fe /spec tree: 34ba74 active_content_spec.rb blob: a738fc Saturday, September 12, 2009 11
  • 12. Object Database - Commit commit: 8d1ab4 commit: 61db26 / tree: 1fba94 tree: 1fba94 Rakefile blob: 2e6f9b blob: 41d300 /lib tree: 3ef95a tree: 3ef95a active_content.rb blob: 7034fe blob: 7034fe /spec tree: 34ba74 tree: 34ba74 active_content_spec.rb blob: a738fc blob: 2a03fb Saturday, September 12, 2009 12
  • 13. Object Database - Tag tag: 6ee1f2 commit: 8d1ab4 / tree: 1fba94 Rakefile blob: 2e6f9b /lib tree: 3ef95a active_content.rb blob: 7034fe /spec tree: 34ba74 active_content_spec.rb blob: a738fc Saturday, September 12, 2009 13
  • 14. Object Database - Resumindo Saturday, September 12, 2009 14
  • 15. Object Database - Resumo • Blob é o menor objeto do git • Tree contém Trees e Blobs • Commit contém Commits, Trees e Blobs • Tags contém/apontam um Commit Saturday, September 12, 2009 15
  • 16. References .git/refs/heads/master master HEAD commit: 8d1ab4 / tree: 1fba94 Rakefile blob: 2e6f9b /lib tree: 3ef95a active_content.rb blob: 7034fe /spec tree: 34ba74 active_content_spec.rb blob: a738fc Saturday, September 12, 2009 16 Um branch é um ponteiro para um commit. Quando se avança um branch adicionando commits, o que está acontecendo, por baixo dos panos, é mudar o ponteiro do branch para um novo commit.
  • 17. Staging Index lib.rb Untracked $ git add lib.rb lib.rb Staged $ git commit -m “lib.rb” lib.rb Commited Saturday, September 12, 2009 17
  • 19. Criação de repositórios Criando um novo repositório $ rails my_blog ... $ cd my_blog $ git init $ git add . $ git commit -m “Initial commit” Criando um repositório a partir de um outro $ git clone git://github.com/tinogomes/my_blog_app_with_bug.git $ cd my_blog_app_with_bug $ git branch master Saturday, September 12, 2009 19
  • 20. Trabalhando em um branch remoto $ cd my_blog_app_with_bug $ git checkout -b refactoring origin/refactoring ... após modificações $ echo tmp > .gitignore $ git add . $ git commit -m “outras modificacoes” $ git pull $ git push origin refactoring Saturday, September 12, 2009 20
  • 21. Indo além do flow básico Saturday, September 12, 2009 21
  • 22. Adicionando arquivos $ git add <dir> $ git add <dir>/<arquivo> $ git add *.rb $ git add . (cuidado) Saturday, September 12, 2009 22
  • 23. Trabalhando com branch local $ cd my_blog_app_with_bug $ git branch meu_branch_local ... $ git checkout master $ git pull . master $ git push origim master $ git branch -d meu_branch_local Saturday, September 12, 2009 23
  • 24. Navegando pelo histórico $ git log --stat commit 7f5a85113381e8c0d16e4679c4e5a81a4eb000b8 Author: Celestino Gomes <celestino@HDU15121-ADIGITAL.local> Date: Sat Sep 12 02:22:52 2009 -0300 Initial commit README | 243 ++ Rakefile | 10 + app/controllers/application_controller.rb | 10 + app/helpers/application_helper.rb | 3 + config/boot.rb | 110 + ... test/performance/browsing_test.rb | 9 + test/test_helper.rb | 38 + 41 files changed, 8452 insertions(+), 0 deletions(-) Saturday, September 12, 2009 24
  • 25. Navegando pelo histórico $ git log -p --no-merges commit 7f5a85113381e8c0d16e4679c4e5a81a4eb000b8 Author: Celestino Gomes <celestino@HDU15121-ADIGITAL.local> Date: Sat Sep 12 02:22:52 2009 -0300 Initial commit diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb new file mode 100644 index 0000000..4b60558 --- /dev/null +++ b/test/performance/browsing_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' +require 'performance_test_help' + +# Profiling results for each test method are written to tmp/performance. +class BrowsingTest < ActionController::PerformanceTest + def test_homepage + get '/' + end +end Saturday, September 12, 2009 25
  • 26. Navegando pelo histórico $ git log --pretty=oneline 7f5a85113381e8c0d16e4679c4e5a81a4eb000b8 Initial commit $ git blame app/helpers/application_helper.rb ^7f5a851 (Celestino Gomes 2009-09-12 02:22:52 -0300 1) module ApplicationHelper ^7f5a851 (Celestino Gomes 2009-09-12 02:22:52 -0300 2) end Saturday, September 12, 2009 26
  • 27. Manipulando o índice Remove do stage index $ git reset [<commit>] Limpa os arquivos, inclusive os unstagged $ git reset --hard [<commit>] Coloca os arquivos de volta para o stage index $ git reset --soft [<commit>] Permite alterar o último commit $ git commit --amend Saturday, September 12, 2009 27 <commit> - default HEAD
  • 28. A diferença entre merge e rebase master sprint_branch C1 C2 C4 C3 C5 Saturday, September 12, 2009 28
  • 29. A diferença entre merge e rebase master sprint_branch C1 $ git checkout master $ git pull . sprint_branch C2 C4 ou $ git checkout master C3 C5 $ git fetch $ git merge sprint_branch C6 merge commit Saturday, September 12, 2009 29
  • 30. A diferença entre merge e rebase master C1 $ git checkout master $ git pull --rebase . sprint_branch C2 C4 ou $ git checkout master C3 C5 $ git fetch $ git rebase sprint_branch C4’ C5’ Saturday, September 12, 2009 30
  • 31. Usando o stash $ git stash $ git stash list $ git stash show stash@{0} $ git stash apply $ git stash drop stash@{0} Saturday, September 12, 2009 31
  • 32. Revertendo commits $ git revert <commit_hash> $ git revert -n <commit_hash> Saturday, September 12, 2009 32 -n para deixar a reversão no index
  • 33. Buscando por bugs $ git bisect start [<bad> [<good>]] $ git bisect good | bad [<rev>] $ git bisect skip [(<rev>|<range>)] $ git bisect reset $ git bisect run <cmd | script> Saturday, September 12, 2009 33 1) Primeiro é necessário identificar pontos (commits) bons e ruins para começar a caça. Usar $ git log 2) $ git bisect run my_script - Note that the "run" script (my_script in the above example) should exit with code 0 in case the current source code is good. Exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad.
  • 34. Limpando a sujeira do dia-a-dia Remover arquivos/diretórios não trackeados $ git clean -d -f Remover um branch remoto $ git push origin :<branch_remoto> Limpar todo o stash $ git stash clear Saturday, September 12, 2009 34 clean para remover arquivos/diretórios não trackeados, push origin :<branch> limpa branches remotos, stash para limpar todo o stash
  • 35. Funciona no Windows? • Somente através do cygwin ou msysGit Saturday, September 12, 2009 35
  • 36. Referências • http://git.or.cz/gitwiki/GitDocumentation • http://www.kernel.org/pub/software/scm/git/docs/ • http://blog.tinogomes.com/2008/05/11/instalando-e-usando-git- no-windows-xp/ • http://github.com Saturday, September 12, 2009 36
  • 38. Mais sobre mim • http://blog.tinogomes.com Saturday, September 12, 2009 38