---

Gettin' Git

Fundamental Bits

The SHA

4b825dc642cb6eb9a060e54bf8d69288fbee4904

SHA-1

Takes some bunch of data, spits out the number.

sha-1.png

sha-2.png

Short SHA

5ab7499

(it's the beginning of the long SHA)

The Commit

commit-1.png

% git log --pretty=raw

commit 24b00b520504c601eb2712949675a6be9660c939
tree 6d2b3d77b57c4abe9b90fb9649a155f39dcefda1
parent adca7904e00a2513c8eae9ba0fff9afb9732ed49
author Ed Chastain <echastain@blinkx.com> 1423527063 -0800
committer Ed Chastain <echastain@blinkx.com> 1423527063 -0800

A Big Tree of Changes

commit-2.png

Refs

commit-4.png

Remotes

  • Refers to whole repos
  • local "remote" is implicit
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@bitbucket.org:allenluce/ufe2.0.git
[remote "upstream"]
        fetch = +refs/heads/*:refs/remotes/upstream/*
        url = git@bitbucket.org:blinkxdev/ufe2.0.git
[branch "develop"]
        remote = origin
        merge = refs/heads/develop

Merge commit

commit-3.png

Merge commit

commit-5.png

Merging

one-branch.png

Merging

two-branch.png

Merging

many-master.png

Merge Hell

merge-hell.gif

Rebasing

Rebasing basics

  • Merging lets you tie branches together.
  • Rebasing lets you cut them apart.
  • Rebasing rewrites history
  • Changes the SHAs of commits

The Rewriting Process

rewriting2.png

The Rewriting Process

rewriting3.png

The Rewriting Process

rewriting.png

The Rewriting Process

rewriting4.png

Pros/Cons

  • The Good
    • Lets you straighten things out
  • The Bad
    • Rewrites history.

Rules of Thumb

  • Private? Yes.
  • Public? No.

Code Archeology

  • git blame 02fabc8~ SomeFile.php
  • git gui blame
  • blame parent

Blaming

-w to ignore whitespace changes -M to turn on the copy/paste detector -C to turn on the multifile copy-paste detector

Pickaxe

git log -p -S'ConversionKeys' phpfile.php

Bisection

  • Read the manual. Way useful.

Git Never Forgets (mostly)

  • reflog is your lifeline.
  • Where'd it go?

reflog.png

Reflog Knows

49dd9d8 HEAD@{2}: checkout: moving from 1eb5def41cfb1e1d81e6e884059e1878302e3a6a to 49dd9d8a65bc4
1eb5def HEAD@{3}: checkout: moving from develop to upstream/feature/UFE-2097
509d11f HEAD@{4}: merge refs/remotes/upstream/develop: Fast-forward
5e0d4db HEAD@{5}: checkout: moving from feature/UFE-2097 to develop

reflog.png

ReReRe

  • If you're doing a lot of the same merges, use it.