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

Git - simple overview and architecture

Git - simple overview and architecture

Why Git is distributed? How the internals of Git works? Also a lot on Octocats :)

Dulitha Wijewantha (Chan)

April 03, 2014
Tweet

More Decks by Dulitha Wijewantha (Chan)

Other Decks in Programming

Transcript

  1. Different from SVN 1. No VC server 2. All VC

    commands are local 3. Can have multiple remote repositories
  2. In Details • .git directory • Git objects • Git

    index • Git branch • Git merge • Git rebase • Git refes • few advance stuff
  3. .git directory • Used to hold everything regarding git •

    This folder is only present in the root of the repository • If you delete the .git folder - repository is deleted • Running a git commands affects the .git folder
  4. blob • Bunch of bytes (source code, images, pdf etc)

    • A hash is generated per blob • A blob can be accessed using the hash
  5. Helpful commands • git hash-object - used to add file

    to git datastore • git cat-file - used to view files in git using hash • git ls-files - used to view tree object
  6. tree • represents a file system/ directory • links blobs

    and other trees • A hash is generated for tree • A tree can be viewed using the hash
  7. $ git cat-file -p master^{tree} 100644 blob a906cb2a4a904a152e80877d4088654daad0c859 README 100644

    blob 8f94139338f9404f26296befa88755fc2598c289 Rakefile 040000 tree 99f1a6d12cb4b6f19c8655fca46c3ecf317074e0 lib
  8. commit • contains info of committer (username & email) •

    contains the hash of the tree object that represented the state of commit
  9. • contains parent commit hash • contains a comment •

    a commit object is created from the index commit cont.
  10. tags • used to name commit objects • contains name

    of tag • contains commit hash • contains a tag message
  11. Git index • A staging area to add changes •

    Before committing - you have to place changes to the index
  12. Git index cont. • content is stored temporarily in a

    binary file - .git/index • can be used to add partial parts of a file
  13. Checking out code • Checkout to working directory • Checkout

    branches, tags, commits, remotes • Checkout to commit to new branch
  14. Now where? • .git directory • Git objects • Git

    index • Git branch • Git merge • Git rebase • Git refes • few advance stuff
  15. Branches • Default branch is master • branching makes a

    pointer to a commit • current branch = HEAD
  16. Branches cont. git branch branch_name git checkout branch_name • branch

    is created making the current branch the parent
  17. Branches cont. • located at .git/refs/heads • the filename is

    the name of the branch and file contains the hash of the most recent commit object
  18. Branches cont. • Inexpensive to create since it’s a file

    creation locally • Branching strategies are there to simplify git branching workflows
  19. Merging • one branch gets merged to another • Git

    will try it’s best to merge safely • flags to override behavior
  20. Merging cont. git merge hotfix • merging can happen for

    branches • merge specified branch to current branch
  21. Merging • In doubt Git will throw errors :) and

    make conflicts • When conflicts happen working directory is not safe to be commited.
  22. don’t panic if you see this $ git merge abc

    Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
  23. Merge conflict resolution • git status to figure out what

    files have conflicts • Open up the files that has the conflict and navigate to the area that has <<<<<<< HEAD
  24. Merge conflict resolution cont. • commit changes after resolving •

    commit message is included by default • Now the git commit objects will point to a git tree that has the resolved changes
  25. Rebasing • an option to base changes from a different

    branch. • Commits in one branch can be applied to another branch • Rebasing allows a linear commit history
  26. Refs and Remotes • online repo is called remote •

    local repo can have multiple remotes • found in .git/refs/remotes/ • local repo has all commits of all remotes
  27. Refs and Remotes cont. git push origin master git pull

    origin master • set of commands present to work with remotes git fetch
  28. Refs and Remotes cont. • how remotes, remote branches, local

    branches interact is called refspace. • refspace can be customized • refs are in .git/config file
  29. Example :- .git/config [remote "dev"] url = [email protected]:wso2-dev/product-emm.git fetch =

    +refs/heads/*:refs/remotes/dev/* [branch "master"] remote = dev merge = refs/heads/master [remote "official"] url = [email protected]:wso2/product-emm.git fetch = +refs/heads/*:refs/remotes/official/* [remote "own"] url = [email protected]:dulichan/product-emm.git fetch = +refs/heads/*:refs/remotes/own/*
  30. Packfiles • Git packs blobs with zlib - upto 60%

    compression for text • Git stores data in git objects - blobs, trees, commits, tags • When storing blobs - previous data is intact and a new object is created if the content changes. ◦ Eg:- 14K file example • To be efficient Git packs the data in deltas. Git does this management automatically • To manually manage repacking - git gc
  31. Credits • All the Octocats belong to Github <3 •

    Diagrams are from Git documentation