six3 getting git

339
Getting Git by Daniel Cox

Upload: danielpcox

Post on 16-May-2015

571 views

Category:

Technology


0 download

DESCRIPTION

A talk I gave at Six3 on Git.

TRANSCRIPT

Page 1: Six3 Getting Git

Getting Gitby Daniel Cox

Page 2: Six3 Getting Git

Getting Gitby Daniel Cox

(who is enormously grateful to Scott Chacon for half of these slides)

Page 3: Six3 Getting Git

THE MASTER PLAN• What is Git?• Understanding Git– The Basics– The Git Object Database– History Inspection– Branching Workflows– Collaboration– Advanced Stuff– Troubleshooting

• Review• Resources• Questions

Page 4: Six3 Getting Git

THE MASTER PLAN• What is Git?• Understanding Git– The Basics– The Git Object Database– History Inspection– Branching Workflows– Collaboration– Advanced Stuff– Troubleshooting

• Review• Resources• Questions

3 minutes

15 hours

2 minutes

3 minutes

20 minutes

Page 5: Six3 Getting Git

What is Git?

• Git is a Version Control System– Versioning– Collaboration

• Other things Git is:– A very simple content tracker– A key/value object database with a VCS front-end– A toolkit

Page 6: Six3 Getting Git

What is Git?

"I'm an egotistical b[------], and I name all my projects after myself. First 'Linux', now 'git'.”

-- Linus Torvalds

Page 7: Six3 Getting Git
Page 8: Six3 Getting Git
Page 9: Six3 Getting Git

the “plumbing”

Page 10: Six3 Getting Git
Page 11: Six3 Getting Git
Page 12: Six3 Getting Git

the “porcelain”

Page 13: Six3 Getting Git
Page 14: Six3 Getting Git

What is Git?

Something Git is not: Subversion

• Much faster for a slightly larger disk footprint(stores snapshots instead of deltas)

• Can do a bunch of stuff without a network connection

• Cheap branching and merging• No .svn directory clutter• And quite a bit more, since Git was not designed to

be the latest evolution of rcs -> cvs -> svn -> …

Page 15: Six3 Getting Git

What is Git?

What Git is on your hard drive.

$> mkdir foobar$> cd foobar$> git init

$> tree –a .git

Page 16: Six3 Getting Git

What is Git?

.git├── HEAD├── config├── description├── hooks│   ├── applypatch-msg.sample│   ├── commit-msg.sample│   ├── post-update.sample│   ├── pre-applypatch.sample│   ├── pre-commit.sample│   ├── pre-rebase.sample│   ├── prepare-commit-msg.sample│   └── update.sample├── info│   └── exclude├── objects│   ├── info│   └── pack└── refs ├── heads └── tags

8 directories, 12 files

$> tree –a .git

Page 17: Six3 Getting Git

What is Git?.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags

14 directories, 20 files

$> touch README$> git add .$> git commit –m “initial commit”

$> tree –a .git

Page 18: Six3 Getting Git

What is Git?.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags

14 directories, 20 files

$> touch README$> git add .$> git commit –m “initial commit”

$> tree –a .git

Page 19: Six3 Getting Git

What is Git?.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags

14 directories, 20 files

$> touch README$> git add .$> git commit –m “initial commit”

$> tree –a .git

Page 20: Six3 Getting Git

What is Git?.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags

14 directories, 20 files

$> touch README$> git add .$> git commit –m “initial commit”

$> tree –a .git

Page 21: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History Inspection• Branching Workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 22: Six3 Getting Git

The Basics

The most basic tasks you need to be able to do with Git are thus:• git init• git status• git add• git commit

Page 23: Six3 Getting Git

The Basics

The most basic tasks you need to be able to do with Git are thus:• git init• git status• git add• git commit• git tag

Page 24: Six3 Getting Git
Page 25: Six3 Getting Git
Page 26: Six3 Getting Git
Page 27: Six3 Getting Git

$> git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: README# new file: Rakefile# new file: lib/mylib.rb#

Page 28: Six3 Getting Git

$> git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: README# new file: Rakefile# new file: lib/mylib.rb#

Page 29: Six3 Getting Git
Page 30: Six3 Getting Git
Page 31: Six3 Getting Git
Page 32: Six3 Getting Git

$> git tag first_commit$>

Page 33: Six3 Getting Git

git init

(work work work work)

git status

git add --all

git status

git commit

(work work work)

git status

git add …

git status

git commit

git tag

Page 34: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History inspection• Branching workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 35: Six3 Getting Git

The Git Object Database

Page 36: Six3 Getting Git

The Git Object Database

• Key / Value <=> SHA1 / Content

Page 37: Six3 Getting Git

The Git Object Database

• Key / Value <=> SHA1 / Content• All objects go under the “objects” directory

under .git.git├── HEAD├── config├── description├── hooks│   ├── …├── info│   └── exclude├── objects│   ├── info│   └── pack└── refs ├── heads └── tags

8 directories, 12 files

there

Page 38: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags

14 directories, 20 files

Page 39: Six3 Getting Git

The Git Object Database

• Key / Value <=> SHA1 / Content• All objects go under the “objects” directory

under .git• There are only four kinds of objects that Git

stores during normal use:– blobs (≈files)– trees (≈directories)– commits– tags

Page 40: Six3 Getting Git

The Git Object Database

all git objects are stored as follows

Page 41: Six3 Getting Git

The Git Object Database

content

Page 42: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

content

Page 43: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

sha = Digest::SHA1.hexdigest(new_content)

content

Page 44: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

Page 45: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

Page 46: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

path = “.git/objects/82/4aed035c0aa75d64c...”

Page 47: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

path = “.git/objects/82/4aed035c0aa75d64c...”

File.open(path, ‘w’) {|f| f.write(compressed)}

Page 48: Six3 Getting Git

The Git Object Database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

path = “.git/objects/82/4aed035c0aa75d64c...”

File.open(path, ‘w’) {|f| f.write(compressed)}

“loose” format

Page 49: Six3 Getting Git

The Git Object Database

git gc

Page 50: Six3 Getting Git

The Git Object Database

git gc

same file with minor differences

Page 51: Six3 Getting Git

The Git Object Database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

same file with minor differences

Page 52: Six3 Getting Git

The Git Object Database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

.git/objects/pack/pack-999727..9f600.pack

.git/objects/pack/pack-999727..9f600.idx

same file with minor differences

Page 53: Six3 Getting Git

The Git Object Database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

.git/objects/pack/pack-999727..9f600.pack

.git/objects/pack/pack-999727..9f600.idx

same file with minor differences

Page 54: Six3 Getting Git

The Git Object Database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

.git/objects/pack/pack-999727..9f600.pack

.git/objects/pack/pack-999727..9f600.idx

same file with minor differences

“packed” format

Page 55: Six3 Getting Git

The Git Object Database

There are only four types of Git objects

Page 56: Six3 Getting Git

The Git Object Database

blob

Page 57: Six3 Getting Git

The Git Object Database

blob tree

Page 58: Six3 Getting Git

The Git Object Database

commit

blob tree

Page 59: Six3 Getting Git

The Git Object Database

commit tag

blob tree

Page 60: Six3 Getting Git

The Git Object Database

blob

Page 61: Six3 Getting Git

The Git Object Database

blob

Page 62: Six3 Getting Git

The Git Object Database

blob

Page 63: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 64: Six3 Getting Git

The Git Object Database

content

zlib::deflate

Page 65: Six3 Getting Git

The Git Object Database

content

header

zlib::deflate

Page 66: Six3 Getting Git

The Git Object Database

content

header

compress zlib::deflate

Page 67: Six3 Getting Git

The Git Object Database

content

header

compress

object

zlib::deflate

Page 68: Six3 Getting Git

The Git Object Database

commit tag

blob tree

Page 69: Six3 Getting Git

The Git Object Database

tree

Page 70: Six3 Getting Git

The Git Object Database

tree

Page 71: Six3 Getting Git

The Git Object Database

tree

Page 72: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 73: Six3 Getting Git

The Git Object Database

filename“inode” info

zlib::deflate

Page 74: Six3 Getting Git

The Git Object Database

“block pointer”typemode

zlib::deflate

Page 75: Six3 Getting Git

The Git Object Database

commit tag

blob tree

Page 76: Six3 Getting Git

The Git Object Database

commit

Page 77: Six3 Getting Git

The Git Object Database

commit

Page 78: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 79: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 80: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 81: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 82: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 83: Six3 Getting Git

The Git Object Database

Page 84: Six3 Getting Git

The Git Object Database

commit tag

blob tree

Page 85: Six3 Getting Git

The Git Object Database

tag

Page 86: Six3 Getting Git

The Git Object Database

tag

Page 87: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 88: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 89: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 90: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 91: Six3 Getting Git

The Git Object Database

zlib::deflate

Page 92: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags

14 directories, 20 files

$> touch README$> git add .$> git commit –m “initial commit”

$> tree –a .git

$> git init

Page 93: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> touch README$> git add .$> git commit –m “initial commit”

$> git tag –a taggy(opens editor to write annotation)

$> tree –a .git

$> git init

Page 94: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> touch README$> git add .$> git commit –m “initial commit”

$> git tag –a taggy(opens editor to write annotation)

$> tree –a .git

$> git init

Page 95: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

Page 96: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p c7dcf9ef54b124542e958c62866d8724471d77d2object cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52type committag taggytagger Daniel Cox <[email protected]> Sat Jan 5 23:47:45 2013 -0500

a thrilling annotation message$>

the tag pointing to the commit

Page 97: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p c7dcf9ef54b124542e958c62866d8724471d77d2object cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52type committag taggytagger Daniel Cox <[email protected]> Sat Jan 5 23:47:45 2013 -0500

a thrilling annotation message$>

the tag pointing to the commit

Page 98: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52

Page 99: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52tree 543b9bebdc6bd5c4b22136034a95dd097a57d3ddauthor Daniel Cox <[email protected]> 1357417822 -0500committer Daniel Cox <[email protected]> 1357417822 -0500

init$>

the commit pointing to the tree

Page 100: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52tree 543b9bebdc6bd5c4b22136034a95dd097a57d3ddauthor Daniel Cox <[email protected]> 1357417822 -0500committer Daniel Cox <[email protected]> 1357417822 -0500

init$>

the commit pointing to the tree

Page 101: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52tree 543b9bebdc6bd5c4b22136034a95dd097a57d3ddauthor Daniel Cox <[email protected]> 1357417822 -0500committer Daniel Cox <[email protected]> 1357417822 -0500

init$>

the commit pointing to the tree

Page 102: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p 543b9bebdc6bd5c4b22136034a95dd097a57d3dd

Page 103: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p 543b9bebdc6bd5c4b22136034a95dd097a57d3dd100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391README$>

the tree with one file in it

Page 104: Six3 Getting Git

The Git Object Database.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

$> git cat-file –p e69de29bb2d1d6434b8b29ae775ad8c2e48c5391$>

the empty file blob

Page 105: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History inspection• Branching workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 106: Six3 Getting Git

History Inspection

Page 107: Six3 Getting Git

History Inspection

• git log– shows you a nice ordered list of your commits and

their messages• git diff– allows you to see the difference between two

versions of a file, or between two entire commits• git show– ask to see something git is holding for you.

commits, trees, tags, blobs, and any treeish

Page 108: Six3 Getting Git

git log

Page 109: Six3 Getting Git
Page 110: Six3 Getting Git
Page 111: Six3 Getting Git
Page 112: Six3 Getting Git
Page 113: Six3 Getting Git
Page 114: Six3 Getting Git
Page 115: Six3 Getting Git
Page 116: Six3 Getting Git
Page 117: Six3 Getting Git

git diff

Page 118: Six3 Getting Git

git diff (treeish1) (treeish2)

Page 119: Six3 Getting Git

the treeish

Page 120: Six3 Getting Git

the treeish

alternate ways to refer to objects or ranges of objects

Page 121: Six3 Getting Git

Treeish

• full sha-1 • partial sha-1 • branch or tag name• date spec • ordinal spec• carrot parent• tilde spec • tree pointer• blob spec• ranges

Page 122: Six3 Getting Git

Full SHA1

6e453f523fa1da50ecb04431101112b3611c6a4d

Page 123: Six3 Getting Git

Partial SHA1

6e453f523fa1da50ecb04431101112b3611c6a4d

6e453f523fa1da50

6e453

Page 124: Six3 Getting Git

Branch, Remote or Tag Name

v1.0

master

origin/testing

Page 125: Six3 Getting Git

Date Spec

master@{yesterday} master@{1 month ago}

Page 126: Six3 Getting Git

Ordinal Spec

master@{5}

5th prior value of ‘master’

Page 127: Six3 Getting Git

Carrot Parent

master^2

2nd parent of ‘master’

Page 128: Six3 Getting Git

Tilde Spec

master~2

2nd generation grandparent of ‘master’

Page 129: Six3 Getting Git

Tree Pointer

master^{tree}

tree that ‘master’ points to

Page 130: Six3 Getting Git

Blob Spec

master:/path/to/file

blob of that file in ‘master’ commit

Page 131: Six3 Getting Git

Ranges

ce0e4..e4272

everything between two commits

Page 132: Six3 Getting Git

Ranges

ce0e4..

everything since a commit

Page 133: Six3 Getting Git

One Especially Useful One

origin/master..HEADor just

origin/master..

everything you’ve done since the last time you pulled

Page 134: Six3 Getting Git

History Inspection

• git log• git diff• git show

Page 135: Six3 Getting Git

History Inspection

• git log• git diff• git show

$> git show taggy

tag taggyTagger: Daniel Cox <[email protected]>Date: Sat Jan 5 23:47:45 2013 -0500

a thrilling annotation message

commit cc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52Author: Daniel Cox <[email protected]>Date: Sat Jan 5 15:30:22 2013 -0500

init

diff --git a/README b/READMEnew file mode 100644index 0000000..e69de29

Page 136: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History inspection• Branching workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 137: Six3 Getting Git

Branching Workflows

Page 138: Six3 Getting Git

Branching Workflows

• git branch• git checkout• git merge• git rebase

Page 139: Six3 Getting Git

Branching Workflows

• git branch– list, create or delete branches

Page 140: Six3 Getting Git

Branching Workflows

• git branch– list, create or delete branches

$> git branch new_branch$>

Page 141: Six3 Getting Git

Branching Workflows

• git branch– list, create or delete branches

$> git branch* master new_branch

Page 142: Six3 Getting Git

Branching Workflows

• git branch– list, create or delete branches

$> git branch -d new_branch$>

$> git branch -D new_branch$>

Gentle

Drastic

Page 143: Six3 Getting Git

Branch Reference?

Page 144: Six3 Getting Git

Branch Reference?

commit tag

blob tree

Page 145: Six3 Getting Git

No Branch References Here

commit tag

blob tree

immutable

Page 146: Six3 Getting Git

No Branch References Here

commit tag

blob tree

can’t be muted

immutable

Page 147: Six3 Getting Git

Referenceslightweight, movablepointers to a commit

Page 148: Six3 Getting Git

Referenceslightweight, movablepointers to a commit

stored in .git/refs/*as simple files

Page 149: Six3 Getting Git

References.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   ├── master    │   └── new_branch └── tags └── taggy

15 directories, 24 files

Page 150: Six3 Getting Git

References.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   ├── master    │   └── new_branch └── tags └── taggy

15 directories, 24 files

Which branch you’re “on”

Branch References!

Page 151: Six3 Getting Git

References.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   ├── master    │   └── new_branch └── tags └── taggy

15 directories, 24 files

Which branch you’re “on”

Branch References!

$> cat .git/refs/heads/mastercc9fc8c4ea4df4f245103cbe80c35bfa2eb07e52

$> cat .git/HEADref: refs/heads/master

Page 152: Six3 Getting Git

The Complete Git Data Model

Page 153: Six3 Getting Git

Branching Workflows.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   ├── master    │   └── new_branch └── tags └── taggy

15 directories, 24 files

Which branch you’re “on”

$> cat .git/HEADref: refs/heads/master

Page 154: Six3 Getting Git

Branching Workflows.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   ├── master    │   └── new_branch └── tags └── taggy

15 directories, 24 files

Which branch you’re “on”

$> cat .git/HEADref: refs/heads/master

$> git checkout new_branchSwitched to branch ‘new_branch’$> cat .git/HEADref: refs/heads/new_branch

Page 155: Six3 Getting Git

Branching Workflows

Two notes:

• git checkout –b yet_another_branch

• “checkout” is different in subversion

Page 156: Six3 Getting Git

Branching Workflows

• git branch• git checkout• git merge• git rebase

Page 157: Six3 Getting Git

Branching and Merging

Page 158: Six3 Getting Git

HEAD

Page 159: Six3 Getting Git

git checkout -b experiment

HEAD

Page 160: Six3 Getting Git

git commit

HEAD

Page 161: Six3 Getting Git

git commitgit commit

HEAD

Page 162: Six3 Getting Git

HEAD

git checkout master

Page 163: Six3 Getting Git

git commitHEAD

Page 164: Six3 Getting Git

git tag -a ‘v1.1’

HEAD

Page 165: Six3 Getting Git

git checkout experimentgit commit

HEAD

Page 166: Six3 Getting Git

git checkout mastergit merge experiment

HEAD

Page 167: Six3 Getting Git

Merge Conflicts

<<<<<<< targetbranchSHAtarget branch changesfoo foo foo=======source branch changesbar bar bar>>>>>>> sourcebranchSHA

Page 168: Six3 Getting Git

Merge Conflicts

<<<<<<< targetbranchSHAtarget branch changesfoo foo foo=======source branch changesbar bar bar>>>>>>> sourcebranchSHA

Page 169: Six3 Getting Git

Merge Conflicts

foo foo foobar bar bar $> git add whatever_file

$> git commit

Page 170: Six3 Getting Git

Branching Workflows

• git branch• git checkout• git merge• git rebase

Page 171: Six3 Getting Git

Rebasing

Page 172: Six3 Getting Git
Page 173: Six3 Getting Git

$> git merge jess

Page 174: Six3 Getting Git
Page 175: Six3 Getting Git
Page 176: Six3 Getting Git
Page 177: Six3 Getting Git

1

2

Page 178: Six3 Getting Git

1

2

Page 179: Six3 Getting Git
Page 180: Six3 Getting Git
Page 181: Six3 Getting Git
Page 182: Six3 Getting Git
Page 183: Six3 Getting Git
Page 184: Six3 Getting Git
Page 185: Six3 Getting Git
Page 186: Six3 Getting Git
Page 187: Six3 Getting Git

“production”

Page 188: Six3 Getting Git

“production”

“trunk”

Page 189: Six3 Getting Git

“production”

“trunk”convention!

Page 190: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History Inspection• Branching Workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 191: Six3 Getting Git

Collaboration

• git remote• git push• git clone• git fetch• git pull

Page 192: Six3 Getting Git

Collaboration

• git remote• git push• git clone• git fetch• git pull

Page 193: Six3 Getting Git
Page 194: Six3 Getting Git
Page 195: Six3 Getting Git

[email protected]:schacon/simplegit2.git

Page 196: Six3 Getting Git
Page 197: Six3 Getting Git
Page 198: Six3 Getting Git
Page 199: Six3 Getting Git
Page 200: Six3 Getting Git
Page 201: Six3 Getting Git
Page 202: Six3 Getting Git
Page 203: Six3 Getting Git
Page 204: Six3 Getting Git

Collaboration

• git remote• git push• git clone• git fetch• git pull

Page 205: Six3 Getting Git

Collaboration

$> git clone [email protected]:danielpcox/Bare-Bones-Platformer.git platformerCloning into 'platformer'...remote: Counting objects: 285, done.remote: Compressing objects: 100% (197/197), done.remote: Total 285 (delta 138), reused 221 (delta 74)Receiving objects: 100% (285/285), 7.46 MiB | 688 KiB/s, done.Resolving deltas: 100% (138/138), done.$>

Page 206: Six3 Getting Git

Collaboration

$> git clone [email protected]:danielpcox/Bare-Bones-Platformer.git platformerCloning into 'platformer'...remote: Counting objects: 285, done.remote: Compressing objects: 100% (197/197), done.remote: Total 285 (delta 138), reused 221 (delta 74)Receiving objects: 100% (285/285), 7.46 MiB | 688 KiB/s, done.Resolving deltas: 100% (138/138), done.$>

Page 207: Six3 Getting Git

Collaboration

$> git clone [email protected]:danielpcox/Bare-Bones-Platformer.git platformerCloning into 'platformer'...remote: Counting objects: 285, done.remote: Compressing objects: 100% (197/197), done.remote: Total 285 (delta 138), reused 221 (delta 74)Receiving objects: 100% (285/285), 7.46 MiB | 688 KiB/s, done.Resolving deltas: 100% (138/138), done.

$> ls platformerGemfileGemfile.lockREADME.mdlevelslibmediaobjectsplatformer.rb

Page 208: Six3 Getting Git

Collaboration

$> git clone [email protected]:danielpcox/Bare-Bones-Platformer.git platformerCloning into 'platformer'...remote: Counting objects: 285, done.remote: Compressing objects: 100% (197/197), done.remote: Total 285 (delta 138), reused 221 (delta 74)Receiving objects: 100% (285/285), 7.46 MiB | 688 KiB/s, done.Resolving deltas: 100% (138/138), done.

$> ls platformerGemfileGemfile.lockREADME.mdlevelslibmediaobjectsplatformer.rb

Page 209: Six3 Getting Git

Collaboration

$> git clone [email protected]:danielpcox/Bare-Bones-Platformer.git platformerCloning into 'platformer'...remote: Counting objects: 285, done.remote: Compressing objects: 100% (197/197), done.remote: Total 285 (delta 138), reused 221 (delta 74)Receiving objects: 100% (285/285), 7.46 MiB | 688 KiB/s, done.Resolving deltas: 100% (138/138), done.

$> git branch* master

Page 210: Six3 Getting Git

Collaboration

• git remote• git push• git clone• git fetch• git pull

Page 211: Six3 Getting Git
Page 212: Six3 Getting Git
Page 213: Six3 Getting Git
Page 214: Six3 Getting Git
Page 215: Six3 Getting Git
Page 216: Six3 Getting Git

…└── refs ├── heads │   └── master ├── remotes │   └── origin | ├── master │   └── HEAD └── …

.git/refs/remotes/nickname/branchname

Page 217: Six3 Getting Git
Page 218: Six3 Getting Git

Collaboration

• git remote• git push• git clone• git fetch• git pull

Page 219: Six3 Getting Git

Collaboration

pull = fetch + merge

Page 220: Six3 Getting Git

Collaboration

• git remote• git push• git clone• git fetch• git pull

Page 221: Six3 Getting Git

remote workflow

Page 222: Six3 Getting Git
Page 223: Six3 Getting Git
Page 224: Six3 Getting Git
Page 225: Six3 Getting Git
Page 226: Six3 Getting Git
Page 227: Six3 Getting Git
Page 228: Six3 Getting Git
Page 229: Six3 Getting Git

multiple remotes

Page 230: Six3 Getting Git
Page 231: Six3 Getting Git

commit

Page 232: Six3 Getting Git

tree

Page 233: Six3 Getting Git

blobs

Page 234: Six3 Getting Git
Page 235: Six3 Getting Git
Page 236: Six3 Getting Git
Page 237: Six3 Getting Git
Page 238: Six3 Getting Git
Page 239: Six3 Getting Git
Page 240: Six3 Getting Git

git remote add nick git://github.com/nickh/project.git

Page 241: Six3 Getting Git

“nick”

git remote add nick git://github.com/nickh/project.git

Page 242: Six3 Getting Git

git remote add jess git://github.com/jessica/project.git

Page 243: Six3 Getting Git

“jess”

git remote add jess git://github.com/jessica/project.git

Page 244: Six3 Getting Git

git fetch nick

Page 245: Six3 Getting Git
Page 246: Six3 Getting Git

git fetch jess

Page 247: Six3 Getting Git
Page 248: Six3 Getting Git
Page 249: Six3 Getting Git
Page 250: Six3 Getting Git
Page 251: Six3 Getting Git
Page 252: Six3 Getting Git
Page 253: Six3 Getting Git
Page 254: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History Inspection• Branching Workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 255: Six3 Getting Git

Advanced Stuff

• the index• hook scripts• grab-bag of useful things

– git add --interactive and patch adding– git stash [--keep-index] to tuck things away for a second– git cherry-pick to pluck just a few cool things someone else

did out of one of their commits– git fsck [--unreachable] as the final defense against lost stuff– git reflog to see the true history– git bisect to find out when an error was introduced

Page 256: Six3 Getting Git

The Index

Page 257: Six3 Getting Git

The Index.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── …└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

Page 258: Six3 Getting Git

The Index.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── …└── refs ├── heads │   └── master └── tags └── taggy

15 directories, 22 files

there it is

Page 259: Six3 Getting Git

index

Page 260: Six3 Getting Git

index

Page 261: Six3 Getting Git

index

Page 262: Six3 Getting Git

what?

Page 263: Six3 Getting Git
Page 264: Six3 Getting Git
Page 265: Six3 Getting Git
Page 266: Six3 Getting Git
Page 267: Six3 Getting Git

git checkout

Page 268: Six3 Getting Git

git checkout

Page 269: Six3 Getting Git

git checkout

Page 270: Six3 Getting Git

git checkout

Page 271: Six3 Getting Git

git checkout

Page 272: Six3 Getting Git

git checkout

Page 273: Six3 Getting Git

git checkout

Page 274: Six3 Getting Git

vim file2

Page 275: Six3 Getting Git

git status

Page 276: Six3 Getting Git

git status

Page 277: Six3 Getting Git

git status

Page 278: Six3 Getting Git
Page 279: Six3 Getting Git

git add file2

Page 280: Six3 Getting Git

git add file2

Page 281: Six3 Getting Git

git add file2

Page 282: Six3 Getting Git

git status

Page 283: Six3 Getting Git

git status

Page 284: Six3 Getting Git

git commit

Page 285: Six3 Getting Git

git commit

Page 286: Six3 Getting Git

git commit

Page 287: Six3 Getting Git

git commit

Page 288: Six3 Getting Git

vim file1 file2 git status

Page 289: Six3 Getting Git

vim file1 file2 git status

Page 290: Six3 Getting Git

vim file1 file2 git status

Page 291: Six3 Getting Git

git add file1

Page 292: Six3 Getting Git

git add file1

Page 293: Six3 Getting Git

git add file1

Page 294: Six3 Getting Git

git status

Page 295: Six3 Getting Git

git status

Page 296: Six3 Getting Git

git status

Page 297: Six3 Getting Git

git commit

Page 298: Six3 Getting Git

git commit

Page 299: Six3 Getting Git
Page 300: Six3 Getting Git

Advanced Stuff

• the index• hook scripts• grab-bag of useful things

– git add --interactive and patch adding– git stash [--keep-index] to tuck things away for a second– git cherry-pick to pluck just a few cool things someone else

did out of one of their commits– git fsck [--unreachable] as the final defense against lost stuff– git reflog to see the true history– git bisect to find out when an error was introduced

Page 301: Six3 Getting Git

Hook Scripts.git├── HEAD├── config├── description├── hooks│   ├── applypatch-msg.sample│   ├── commit-msg.sample│   ├── post-update.sample│   ├── pre-applypatch.sample│   ├── pre-commit.sample│   ├── pre-rebase.sample│   ├── prepare-commit-msg.sample│   └── update.sample├── info│   └── exclude├── objects│   ├── info│   └── pack└── refs ├── heads └── tags

8 directories, 12 files

Page 302: Six3 Getting Git

Hook Scripts.git├── HEAD├── config├── description├── hooks│   ├── applypatch-msg.sample│   ├── commit-msg.sample│   ├── post-update.sample│   ├── pre-applypatch.sample│   ├── pre-commit.sample│   ├── pre-rebase.sample│   ├── prepare-commit-msg.sample│   └── update.sample├── info│   └── exclude├── objects│   ├── info│   └── pack└── refs ├── heads └── tags

8 directories, 12 files

Page 303: Six3 Getting Git

Hook Scripts#!/bin/sh## An example hook script to verify what is about to be committed.# Called by "git commit" with no arguments. The hook should# exit with non-zero status after issuing an appropriate message if# it wants to stop the commit.## To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1then

against=HEADelse

# Initial commit: diff against an empty tree objectagainst=4b825dc642cb6eb9a060e54bf8d69288fbee4904

fi

# If you want to allow non-ascii filenames set this variable to true.allownonascii=$(git config hooks.allownonascii)

.git/hooks/pre-commit.sample :

Page 304: Six3 Getting Git

Advanced Stuff

• the index• hook scripts• grab-bag of useful things

– git add --interactive and patch adding– git stash [--keep-index] to tuck things away for a second– git cherry-pick to pluck just a few cool things someone else

did out of one of their commits– git fsck [--unreachable] as the final defense against lost stuff– git reflog to see the true history– git bisect to find out when an error was introduced

Page 305: Six3 Getting Git

git add -i# On branch master# Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

Page 306: Six3 Getting Git

git add -i# On branch master# Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

$> git add -i staged unstaged path 1: unchanged +1/-0 /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

*** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: helpWhat now> u

Page 307: Six3 Getting Git

git add -i

staged unstaged path 1: unchanged +1/-0 /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.javaUpdate>> 1

Page 308: Six3 Getting Git

git add -i

staged unstaged path* 1: unchanged +1/-0 /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.javaUpdate>>

Page 309: Six3 Getting Git

git add -iupdated one path

*** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: helpWhat now> s

Page 310: Six3 Getting Git

git add -i staged unstaged path 1: +1/-0 nothing /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

*** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: helpWhat now> q

$> git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

Page 311: Six3 Getting Git

git add -i staged unstaged path 1: +1/-0 nothing /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

*** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: helpWhat now> q

$> git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: /src/main/java/gov/ic/dodiis/i2ps/utils/MongoHelper.java

Page 312: Six3 Getting Git

git stash

• git stash• git stash list• git stash pop• git stash apply

Page 313: Six3 Getting Git

git stash --keep-index

Page 314: Six3 Getting Git

git cherry-pick <commit>

Page 315: Six3 Getting Git

git fsck [--unreachable]

Page 316: Six3 Getting Git

git reflog.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── HEAD│   └── refs│   └── heads│   ├── master│   └── new_branch├── objects│   ├── …└── refs ├── heads │   ├── master │   └── new_branch └── tags └── taggy

15 directories, 24 files

$> git reflogcc9fc8c HEAD@{0}: checkout: moving from master to new_branchcc9fc8c HEAD@{1}: commit (initial): init

$> git reflog mastercc9fc8c master@{0}: commit (initial): init

$> git reflog new_branchcc9fc8c new_branch@{0}: branch: Created from master

Page 317: Six3 Getting Git

git bisect

• git bisect start• git bisect bad• git bisect good [<commit>]• git bisect reset

Page 318: Six3 Getting Git

git bisect$> git bisect start$> git bisect bad$> git bisect good v1.0Bisecting: 6 revisions left to test after this[ecb6e1bc347ccecc5f9350d878ce677feb13d3b2] error handling on repo

Page 319: Six3 Getting Git

git bisect$> git bisect start$> git bisect bad$> git bisect good v1.0Bisecting: 6 revisions left to test after this[ecb6e1bc347ccecc5f9350d878ce677feb13d3b2] error handling on repo

$> git bisect goodBisecting: 3 revisions left to test after this[b047b02ea83310a70fd603dc8cd7a6cd13d15c04] secure this thing

Page 320: Six3 Getting Git

git bisect$> git bisect start$> git bisect bad$> git bisect good v1.0Bisecting: 6 revisions left to test after this[ecb6e1bc347ccecc5f9350d878ce677feb13d3b2] error handling on repo

$> git bisect goodBisecting: 3 revisions left to test after this[b047b02ea83310a70fd603dc8cd7a6cd13d15c04] secure this thing

$> git bisect badBisecting: 1 revisions left to test after this[f71ce38690acf49c1f3c9bea38e09d82a5ce6014] drop exceptions table

Page 321: Six3 Getting Git

git bisect$> git bisect goodb047b02ea83310a70fd603dc8cd7a6cd13d15c04 is first bad commitcommit b047b02ea83310a70fd603dc8cd7a6cd13d15c04Author: PJ Hyett <[email protected]>Date: Tue Jan 27 14:48:32 2009 -0800

secure this thing

:040000 040000 40ee3e7821b895e52c1695092db9bdc4c61d1730f24d3c6ebcfc639b1a3814550e62d60b8e68a8e4 M config

Page 322: Six3 Getting Git

git bisect$> git bisect goodb047b02ea83310a70fd603dc8cd7a6cd13d15c04 is first bad commitcommit b047b02ea83310a70fd603dc8cd7a6cd13d15c04Author: PJ Hyett <[email protected]>Date: Tue Jan 27 14:48:32 2009 -0800

secure this thing

:040000 040000 40ee3e7821b895e52c1695092db9bdc4c61d1730f24d3c6ebcfc639b1a3814550e62d60b8e68a8e4 M config

git bisect reset

Page 323: Six3 Getting Git

Understanding Git

• The Basics• The Git Object Database• History Inspection• Branching Workflows• Collaboration• Advanced Stuff• Troubleshooting

Page 324: Six3 Getting Git

Troubleshooting

Page 325: Six3 Getting Git

Troubleshooting

changing your mind about what you want to commit• git reset• git checkout HEAD filename• git reset --hard

Page 326: Six3 Getting Git

Troubleshooting

changing your mind about a commit after you've already committed• git commit --amend

Page 327: Six3 Getting Git

Troubleshootingditch a commit by moving the branch pointer• git reset --hard <target_commit>• git branch -f <branch_name> <target_commit>

Page 328: Six3 Getting Git

Troubleshooting

uncommit things you didn't mean to commit yet (or ever)• git revert - makes a “go back” commit• just move the branch back to an earlier

commit• the nuclear option: git filter-branch

Page 329: Six3 Getting Git

Troubleshooting

how to avoid these problems in the first place:.gitignore

Page 330: Six3 Getting Git

Troubleshooting.gitignore

# ~/.gitconfig file:

(then create a .gitignore in your home dir.

[core]        excludesfile = /Users/your.name/.gitignore

Page 331: Six3 Getting Git

Troubleshooting.gitignore

# ~/.gitconfig file:

(then create a .gitignore in your home dir.

[core]        excludesfile = /Users/your.name/.gitignore

Here's what's in mine:.DS_Store*.svn*~.*.swp.powenv.classpath.project.settingstarget*.class

Check this out for more information

Page 332: Six3 Getting Git

Troubleshooting

problems arising from files being yanked out from underneath the feet of open editors

Page 333: Six3 Getting Git

Troubleshooting• changing your mind about what you want to commit

– git reset, git checkout, git reset --hard• changing your mind about a commit after you've already committed

– git commit --amend• ditch a commit by moving the branch pointer back

– git reset --hard … or git branch -f …• how to uncommit things you didn't mean to commit yet

– git revert– just move the branch back to an earlier commit– nuclear option: filter-branch

• how to avoid these problems in the first place– .gitignore

• problems arising from files being yanked out from underneath the feet of open editors

Page 334: Six3 Getting Git

Review

Page 335: Six3 Getting Git

• git init

• git clone

• git add

• git commit

• git branch

• git checkout

12• git merge

• git remote

• git fetch

• git push

• git diff

• git log + git status

Page 336: Six3 Getting Git

.git, One Last Time.git├── COMMIT_EDITMSG├── HEAD├── config├── description├── hooks│   ├── …├── index├── info│   └── exclude├── logs│   ├── …├── objects│   ├── 54│   │   └── 3b9bebdc6bd5c4b22136034a95dd097a57d3dd│   ├── c7│   │   └── dcf9ef54b124542e958c62866d8724471d77d2│   ├── cc│   │   └── 9fc8c4ea4df4f245103cbe80c35bfa2eb07e52│   ├── e6│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│   ├── info│   └── pack└── refs ├── heads │   ├── master    │   └── new_branch └── tags └── taggy

15 directories, 24 files

Page 337: Six3 Getting Git

Resources• git help [command]

– surprisingly good manual pages, which are also online• git-scm.com/docs and git-scm.com/book

– truly beautiful, clear and illustrated documentation, and has a free book that can answer all of your questions

• GitX– great tool for visualization of branching problems, and for designers who would

rather not interact with the command line• the Getting Git video on Vimeo

– the video that made git click for me, the source for many of my slides, best hour ever spent

• Casey's cheat-sheet– an attachment to the “Git Development Workflow” Six3 Confluence page

• Blog Post: “A Successful Git Branching Model”– excellent blog post on good workflow conventions Casey linked to in the comments

there

Page 338: Six3 Getting Git

The End

Page 339: Six3 Getting Git

Questions?