gitinternals

Upload: doorsuser

Post on 07-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 gitinternals

    1/56

    GIT InternalsPedro Melo

    mailto:[email protected]:[email protected]
  • 8/6/2019 gitinternals

    2/56

    A short GIT History

    2002 Apr 2005: The BitKeeper Wars

    Apr 2005: Episode IV - A New Hope July 2005: Hamano is the new maintainer

    Late 2008: GitHub hits the spotlight

    Im an egotistical bastard, and I nameall my projects after myself.First Linux, now git. Linus

  • 8/6/2019 gitinternals

    3/56

    A short GIT History

    2002 Apr 2005: The BitKeeper Wars

    Apr 2005: Episode IV - A New Hope July 2005: Hamano is the new maintainer

    Late 2008: GitHub hits the spotlight

    Im an egotistical bastard, and I nameall my projects after myself.First Linux, now git. Linus

    Person

    altakeo

    n

  • 8/6/2019 gitinternals

    4/56

    GIT rules (without !!)

    Track content, not changes

    Simple repository

    Complex software Its easier to update the software, complex

    to update all the repos so far

    Git Mantra: http://bit.ly/git-phylosophy

    http://bit.ly/git-phylosophyhttp://bit.ly/git-phylosophyhttp://bit.ly/git-phylosophy
  • 8/6/2019 gitinternals

    5/56

    In other words, I'm right. I'm

    always right, but sometimesI'm more right than other

    times. And dammit, when I say"files don't matter", I'm really

    really Right(tm).Linus

  • 8/6/2019 gitinternals

    6/56

    Strong Points

    Non-Linear development

    Distributed Development Centralized development is a subcase

    Efficiency

    Toolkit Design

  • 8/6/2019 gitinternals

    7/56

    Objects

    Git repositories store objects Stored in the Object Database

    Inside the Git directory .git at the root of your project

    Four major object types

    Objects are compressed for storage (zlib) SHA1 of header+content ID

  • 8/6/2019 gitinternals

    8/56

    The Blob

    Files are stored as blobs Only content, no metadata

  • 8/6/2019 gitinternals

    9/56

    blob [content_size]\0

    Your content goes here after the header

    I like pizza with apples

    Meet the blob

  • 8/6/2019 gitinternals

    10/56

    The tree

    Trees store directories

    Mode, type, pointer and name Recursive, trees can contain trees

    Stored as a simple text file

  • 8/6/2019 gitinternals

    11/56

    tree [content_size]\0100644 blob b5f21a README100644 blob afe433 Makefile.PL040000 tree a42cd0 lib

    Meet the tree

  • 8/6/2019 gitinternals

    12/56

    The commit

    The object that makes history Pointer to a tree and the parent(s)

    commits if any

    Author, committer and commitmessage

  • 8/6/2019 gitinternals

    13/56

    commit [content_size]\0tree 23edfc

    author Pedro Melo 1243036800committer Pedro Melo 1243036800

    commit without a parent

    usually called first commit

    Meet the commit...

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/6/2019 gitinternals

    14/56

    commit [content_size]\0tree fde45c

    parent 3454dfauthor Pedro Melo 1243036932committer Pedro Melo 1243036932

    and we fixed that nasty bug

    after all, they do tend to crop up

    ...and its child the other

    commit

    mailto:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/6/2019 gitinternals

    15/56

    The tag

    A name for a particular commit

    Can contain a message Optionally GPG signed

    Allows for cryptographically securereleases

  • 8/6/2019 gitinternals

    16/56

    tag [content_size]\0

    object 123fectype committag v1tagger Pedro Melo 1243037423

    made it to 1.0!

    Meet the tag

    mailto:[email protected]:[email protected]
  • 8/6/2019 gitinternals

    17/56

    Git Data Model Recap

    Immutable objects

    A file per object Repacked into object packs for efficiency

    Organized as a directed acyclic graph

  • 8/6/2019 gitinternals

    18/56

  • 8/6/2019 gitinternals

    19/56

    proj/Makefile.PLlib/

    Cool.pm

  • 8/6/2019 gitinternals

    20/56

    proj/Makefile.PLlib/

    Cool.pm

  • 8/6/2019 gitinternals

    21/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

  • 8/6/2019 gitinternals

    22/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

  • 8/6/2019 gitinternals

    23/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    24/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    25/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    26/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    27/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    28/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    29/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    30/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

    Cool.pm

  • 8/6/2019 gitinternals

    31/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    32/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    33/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    34/56

    References

    Names for commits

    Mutable, they point to a specific commit

    and move to a new one after eachcommit

    A branch is a reference, a name to acommit

    Special HEAD reference: points to areference

    Name

  • 8/6/2019 gitinternals

    35/56

    Cool.pm

    proj/Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

    Makefile.PLlib/

    Cool.pm

    Makefile.PLlib/

  • 8/6/2019 gitinternals

    36/56

    mas

    ter

    HE

    AD

  • 8/6/2019 gitinternals

    37/56

    mas

    ter

    HE

    AD

  • 8/6/2019 gitinternals

    38/56

    master

    HEAD

    te

    st

  • 8/6/2019 gitinternals

    39/56

    master

    HEAD

    te

    st

  • 8/6/2019 gitinternals

    40/56

    mas

    ter

    HE

    AD

    te

    st

  • 8/6/2019 gitinternals

    41/56

    mas

    ter

    HE

    AD

    te

    st

  • 8/6/2019 gitinternals

    42/56

    master

    HEAD

    t

    est

  • 8/6/2019 gitinternals

    43/56

    masterMerge

  • 8/6/2019 gitinternals

    44/56

    master

    Merge

  • 8/6/2019 gitinternals

    45/56

    t

    est

    Rebase

  • 8/6/2019 gitinternals

    46/56

    t

    est

    Rebase

  • 8/6/2019 gitinternals

    47/56

    masterRebase

  • 8/6/2019 gitinternals

    48/56

    master

    Rebase + Merge

  • 8/6/2019 gitinternals

    49/56

    master

    Rebase + Merge

  • 8/6/2019 gitinternals

    50/56

    Non-SCM uses for Git

    Leverage strengths

    immutable

    over network pulls only missing objects fast checkout (compare to copy, less to

    read)

    easy rollback

  • 8/6/2019 gitinternals

    51/56

    Beware of weak points

    Always stores full copy of files

    not good for backups of DB dumps Full history more disk space

    this might chance as shallow clones gainfuncionality...

  • 8/6/2019 gitinternals

    52/56

    Content distribution

    Updates done in a master, centralrepository

    Hierarchy of slave repositories Fast sync between repositories, fast

    checkout

    Can be automated with hooks Useful if you have lots of static files, faster

    than rsync

  • 8/6/2019 gitinternals

    53/56

    Read-only filesystem

    Design web server that fetch objectsdirectly from the object database

    Compact storage, efficient retrieval Packs of objects also very VM friendly,

    mmap ready Some solutions already available OSS

  • 8/6/2019 gitinternals

    54/56

    Wiki/Ticketing backend

    Use git repository as storage for wiki orticketing systems

    Good match for distributed developement Several solutions already available OSS ... but similar to SCM usages

  • 8/6/2019 gitinternals

    55/56

  • 8/6/2019 gitinternals

    56/56

    About Git

    About Mehttp://simplicidade.org/notes/

    @pedromelo{mailto,xmpp}:[email protected]

    skype:melopthttp://github.com/melo

    http://git-scm.com/Git Internals: http://peepcode.com/products/git-internals-pdf

    Git book: http://progit.org/

    http://www.slideshare.net/melopthttp://github.com/melomailto:[email protected]://www.slideshare.net/melopthttp://github.com/melohttp://peepcode.com/products/git-internals-pdfhttp://git-scm.com/http://git-scm.com/http://www.slideshare.net/melopthttp://github.com/melohttp://github.com/melomailto:[email protected]:[email protected]://simplicidade.org/notes/http://simplicidade.org/notes/http://peepcode.com/products/git-internals-pdf