git

33
Git Some Lernin How To Git For Great Good

Upload: randall-hunt

Post on 10-May-2015

66 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Git

Git Some LerninHow To Git For Great Good

Page 2: Git

Why Version Control?

• Because I Say So.

Page 3: Git

Why Git?

• Because I Say So.

Page 4: Git

Vocabulary• Repository -- Holds the history of all changes

• Commit -- A point in time snapshot of your repo

• Reference -- Something that makes it so you don't have to remember a 40 hexadecimal digit sha1 hash

• Branch -- A pointer to the head of a group of commits

• Remote -- A thing you push to and pull from

• Pull Request -- How you get your code reviewed (unless you're on kernel)

• Github -- Magic

Page 5: Git

Porcelain

Page 6: Git

1. Fork a project

2. Clone your fork

3. Branch

4. Edit some files

5. Commit

6. Repeat 4 and 5 until feature/bug is complete

7. REBASE to create a history that I won't mind reading through

8. Pull any changes that have happened on non-forked master in the interim and rebase on top of those if you want a linear history otherwise do nothing for this step

9. Open pull request from your branch on your fork into the canonical repo's master branch

10. Profit

Page 7: Git

How To Branch

• git checkout -b improvement/unicorns

• git branch bug/voldemort && git checkout bug/voldemort

Page 8: Git

How To Commit

• Edit Some Stuff

• git add -p and git add (DO NOT GIT ADD * or .)

• Review what is in staging with git diff --cached and git status

• git commit

Page 9: Git

Commit Messages

• Start with bug number and short description <70 characters

• Longer description after one blank line

Page 10: Git

Index == Staging

• STAGE EVERYTHING

• Save time later by staging only some logical changes now

Page 11: Git

Demo

Page 12: Git

Refs• N^ goes up N parents (HEAD^, HEAD^100)

• ~ selects merge parents (HEAD~, HEAD~2)

• Mix and match (don't actually though)

• HEAD is hard coded and always points to the current head of whatever branch you have checked out

• Almost everything can be treated as a ref

Page 13: Git

Remotes

[remote "origin"] url = [email protected]:ranman/fancy-project.git fetch = +refs/heads/*:refs/remotes/origin/*

Page 14: Git

Everything is an object(content addressable storage)

Page 15: Git

• Blob (zlib compressed bytes representing a file)

• Tree (a tree where the leaf nodes are blobs)

• Commit (a pointer to: a tree, n parent commits)

• Tag (a pointer to a commit)

• (IGNORE THIS) something something packfiles

Page 16: Git
Page 17: Git
Page 18: Git
Page 19: Git

You're just moving some pointers around.

Page 20: Git

Dat Network

Page 21: Git
Page 22: Git
Page 23: Git

Fancy Random Things

Page 24: Git

Find Lost Stuff

• git reflog

• git fsck [--lost-found]

• git log -G

• git branch --contains SHA-1

Page 25: Git

Find Bugs

• git bisect

Page 26: Git

tig

Page 27: Git

git log branchA ^branchB

Page 28: Git

git log branchA..branchB git log branchB..branchA git log branchA...branchB

Page 29: Git

Undo

• git reset --soft HEAD^

• git reset --hard HEAD^

Page 30: Git

Config

• git config --global help.autocorrect 1

• git config --global rerere.enabled 1

• git config --global color.ui 1

• git diff --word-diff

Page 31: Git
Page 32: Git

gitshots

Page 33: Git