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

Git Internals and Git Rebasing

Git Internals and Git Rebasing

Git Objects & Refs
Git Rebasing - good practices

Boopathi Rajaa

January 08, 2015
Tweet

More Decks by Boopathi Rajaa

Other Decks in Programming

Transcript

  1. git

  2. hash-object • 40 character checksum SHA-1 hash • directory(2) +

    filename(38) • git hash-object ./file • echo “foo” | git hash-object -w —stdin
 # fetch input from stdin; write hash to git db • find .git/objects -type f
  3. cat-file • git cat-file -p 8315faa98d6663204f4ca3b00526c530fd9e2bb4 • echo “test 1”

    > test • git hash-object -w test • echo “test 2” > test • git hash-object -w test • # restores “test 1”
 git cat-file -p 6f670c0fb53f9463760b7295fbb814e965fb20c8 > test
  4. Tree Object • Git stores everything as blobs and trees

    • Trees => (UNIX directories) • Blobs => (inodes / file_contents)
  5. Commit Objects • echo “commit message” | git commit- tree

    <hash> • echo “second message” | git commit- tree <hash> -p <prev_hash> • git log —stat <latest_hash>
  6. This is what happens underneath during git-add & git-commit ?

    • Stores the blob for the files that have changed • Updates the index • Writes out trees • Writes commit objects (referencing top-level trees and commits that came immediately before them) • Updates Refs (upcoming slide)
  7. Refs • .git/refs/heads/ • .git/regs/tags/ • git update-ref refs/heads/master <hash>

    • .git/HEAD => refs/heads/master • git update-ref refs/tags/v1.0 <hash> • cat .git/refs/remotes/origin/master
  8. • Import all commits so our development branch stays updated.

    • from `master` into `dev` and `feat1` branches • from `dev` into `feat1` • Preserve all commits of feature branch; merge it to development branch once it’s completed.
  9. git checkout master git branch --contains dev | xargs -n1

    \ git rebase \ --committer-date-is-author-date \ --preserve-merges \ --onto master dev^
  10. A-B-C-E-F (master) \ D-G————K (dev) \ / H-I (feat1) merge

    feat1 to dev git checkout dev git merge --no-ff feat1 --no-ff ensures that a merge commit is created
  11. Other Gotchas • When to rebase ? • When to

    merge ? • Always git pull with rebase • squash commits before pushing • Keep the number of commits as minimum as possible. • Add tags everywhere for all feature merges