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

Git Internals

Git Internals

Git Internals Keynote for @colognerb

thyphoon

June 21, 2012
Tweet

Other Decks in Programming

Transcript

  1. History In April of 2005, Git was born Developed by

    Linus Torvalds for SCM of Linux “I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.” – Linus Git started out as a collection of lower level functions used in various combinations by shell and perl scripts. Donnerstag, 21. Juni 12
  2. Non-Linear Development is built to be worked on simultaneously by

    many people, having multiple branches developed by individual developers, being merged, branched and re- merged constantly Because of this, branching is incredibly cheap and merging is incredibly easy. Donnerstag, 21. Juni 12
  3. Distributed Development Git is built to make distributed development simple.

    No repository is special or central in Git It works completely offline or with hundreds of remote repositories that can push to and/ or fetch from each other over several simple and standard protocols. Donnerstag, 21. Juni 12
  4. Git Object Types Git objects are the actual data of

    Git There are four main object types in Git Blob Tree Commit Tag Donnerstag, 21. Juni 12
  5. Git Object Types Git objects are the actual data of

    Git There are four main object types in Git Blob Tree Commit Tag Important for understanding Donnerstag, 21. Juni 12
  6. The Blob ./ Rakefile lib/ README simplegit.rb Working Directory Git

    Repository blob : a874b7 blob : a906cb blob : a0a60a Donnerstag, 21. Juni 12
  7. The Tree ./ Rakefile lib/ README simplegit.rb Working Directory Git

    Repository blob : a874b7 blob : a906cb blob : a0a60a tree : 1a738d tree : fe8971 Donnerstag, 21. Juni 12
  8. The Commit ./ Rakefile lib/ README simplegit.rb Working Directory Git

    Repository blob : a874b7 blob : a906cb blob : a0a60a tree : 1a738d tree : fe8971 commit : a11bef Donnerstag, 21. Juni 12
  9. The Commit Contents pointer to a tree author commiter message

    parent commits Donnerstag, 21. Juni 12
  10. The Commit Contents pointer to a tree author commiter message

    parent commits blob commit tree parent Donnerstag, 21. Juni 12
  11. References are simple pointers/references to a particular commit for example

    branches blob commit master tree Donnerstag, 21. Juni 12
  12. The Git Data Model a directed acyclic graph blob commit

    tag HEAD branch remote tree Donnerstag, 21. Juni 12
  13. The Directory if you run git init you will find

    a .git directory in your current directory the .git directory holds all objects and references the .git is the whole repository Donnerstag, 21. Juni 12
  14. Working Directory the working directory is the checkout it is

    a working copy, so it is not important if you switch branches, your working directory content will be changed without a checkout (an empty working directory) this is called a bare git repository Donnerstag, 21. Juni 12
  15. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  16. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  17. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  18. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  19. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  20. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  21. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  22. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  23. blob commit HEAD master tree tree tree blob blob .

    `-lib |-README `-example |-source | `-impl.rb `-example.rb $> modify impl.rb ..... $> git commit -a Donnerstag, 21. Juni 12
  24. blob commit HEAD master tree tree tree blob blob commit

    tree tree tree blob . `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  25. blob commit HEAD master tree tree tree blob blob commit

    tree tree tree blob . `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  26. blob commit HEAD master tree tree tree blob blob commit

    tree tree tree blob . `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  27. blob commit HEAD master tree tree tree blob blob commit

    tree tree tree blob . `-lib |-README `-example |-source | `-impl.rb `-example.rb Donnerstag, 21. Juni 12
  28. blob commit HEAD master tree tree tree blob blob commit

    tree tree tree blob . `-lib |-README `-example |-source | `-impl.rb `-example.rb $> modify README ... $> git commit -a Donnerstag, 21. Juni 12
  29. . `-lib |-README `-example |-source | `-impl.rb `-example.rb blob commit

    tree tree tree blob blob commit tree tree tree blob HEAD master tree blob commit Donnerstag, 21. Juni 12
  30. . `-lib |-README `-example |-source | `-impl.rb `-example.rb blob commit

    tree tree tree blob blob commit tree tree tree blob HEAD master tree blob commit Donnerstag, 21. Juni 12
  31. Branching creating a new branch is simply writing a file

    in the .git/ refs/heads with the SHA-1 of the last commit for that branch ➡ Creating a branch is nothing more than just writing 40 characters to a file. DEMO Donnerstag, 21. Juni 12
  32. C1 HEAD master C0 feature $> write some code ...

    $> git commit -a $> write more code ... $> git commit -a Donnerstag, 21. Juni 12
  33. $> git checkout master $> fixing ... $> git commit

    -a $> git tag t1 C1 HEAD master C0 feature C2 C3 HOTFIX ALERT Donnerstag, 21. Juni 12
  34. $> git checkout feature $> coding ... $> git commit

    -a C1 HEAD master C0 feature C2 C3 C4 t1 Donnerstag, 21. Juni 12
  35. $> git checkout master $> git merge feature C1 HEAD

    master C0 feature C2 C3 C4 t1 C5 Donnerstag, 21. Juni 12
  36. C1 HEAD master C0 feature C2 C3 C4 t1 C5

    C6 Donnerstag, 21. Juni 12
  37. C1 HEAD master C0 feature $> write some code ...

    $> git commit -a $> write more code ... $> git commit -a $> write more code ... $> git commit -a Donnerstag, 21. Juni 12
  38. $> git checkout master $> git merge feature C1 HEAD

    master C0 feature C2 C3 C4 Donnerstag, 21. Juni 12
  39. Remotes Remotes are pointers to branches in other peoples copies

    of the same repository often just one, named origin the master from the origin ist referenced by origin/master Donnerstag, 21. Juni 12
  40. C0 master origin/master $> coding ... $> git commit -a

    $> coding ... $> git commit -a Donnerstag, 21. Juni 12
  41. C1 C0 C2 master origin/master $> git checkout -b tryidea

    $> git merge origin/master --no-commit $> git merge origin/idea --no-commit $> git commit -a CR1 CR3 CR4 CR2 origin/idea Donnerstag, 21. Juni 12
  42. C1 C0 C2 master origin/master CR1 CR3 CR4 CR2 origin/idea

    C3 tryidea $> git checkout master $> git merge tryidea $> git push orgin master Donnerstag, 21. Juni 12
  43. C1 john/master master C0 R1 $john> code ... commit $you>

    code ... commit $you> git pull john master C2 Donnerstag, 21. Juni 12
  44. C1 john/master master C0 R1 C2 R2 C3 C4 Merge

    Commits Donnerstag, 21. Juni 12
  45. C1 john/master master C0 R1 C2 R2 C3 C4 Merge

    Commits lets try the same scenario with rebasing Donnerstag, 21. Juni 12
  46. C1 john/master master C0 R1 C2 C0:C1 $john> code ...

    commit $you> code ... commit Donnerstag, 21. Juni 12
  47. C1 john/master C0 R1 R1:C2 R2 C2 master C5 C4

    C3 C2:C3 Donnerstag, 21. Juni 12
  48. C1 john/master master C0 R1 C4 R2 C2 C1 john/master

    master C0 R1 C2 R2 C3 C4 fetch and merge rebase C5 C3 Donnerstag, 21. Juni 12
  49. rebase instead of merge normally a pull is a fetch

    and a merge you can change it to be a fetch and a rebase git config branch.autosetuprebase always/never/local/ remote or you can call git pull --rebase Donnerstag, 21. Juni 12
  50. Credits heavily based on Git Internals PDF by Scott Chacon

    from PeepCode (https:// peepcode.com/products/git-internals-pdf) and some own experience Donnerstag, 21. Juni 12
  51. About Me Andi Bade – Galaxy Cats IT Consulting GmbH

    Twitter: @railsbros_andi Blog: thyphoon.github.com Mail: [email protected] Donnerstag, 21. Juni 12