19
“To merge or to rebase, that is the question.” HAMLET Grokking Git with Shakespeare James World – Brighton .NET User Group Sep 2015

Grokking Git with Shakespeare

Embed Size (px)

Citation preview

“To merge or to rebase, that is the question.” HAMLET

Grokking Git with Shakespeare

James World – Brighton .NET User Group Sep 2015

“All the world’s a staging area, and all the commits merely players…”AS YOU LIKE IT

staging areacacheindex

commitref

branchworking treefile system

Repository

git checkout

CopyCopy

Repository

git add

Copy

Repository

git commit

Copy

commit objects

tree objects

blob objects

HEAD

master HEAD feature1

master HEAD feature1

feature2 feature2HEAD^^2master~1^2feature1~2

“A branch, by any other name would smell as sweet.” ROMEO AND JULIET

“Two branches, both alike in dignity.” ROMEO AND JULIET

A

X Y

master

feature1 feature2

“I have merged, and seen the spider.” A WINTER’S TALE

A

X Yfeature1 feature2

Bxmaster

git merge --no-ff feature1

“Jog on, jog on, the fast forward way.” A WINTER’S TALE

A

X Yfeature1feature2master

git merge feature1

“Oh, how this spring of log resembleth… And by and by a double dot takes all away” THE TWO GENTLEMEN OF VERONA

A BA ൘B

A B

git log A..B

“Thou mis-shapen dick!” HENRY VI

git log A...B

A BA ൘B

A B

“We know what we are, but know not what diff we may be.” HAMLET

git diff A..B git diff A...B

A BA B

SAME AS A B

“I see how thine merge would emulate a diamond.”THE MERRY WIVES OF WINDSOR

A

X Y feature2

Bxymaster

git merge feature2

“Rebasing hath made thee a tame snake.” AS YOU LIKE IT

A

X Yfeature1

feature2

master

Y͛�

A

Xfeature1

feature2master Y͛�

git rebase master [feature2] git merge feature2

“What’s done can be reverted.” MACBETH

A

Xfeature1

feature2Y �͛

X �͛master

“Git thee to a repository.” HAMLET

GET HELP:

git help <command name>ADD AN ALIAS:

git config --global --add alias.lg “log --oneline --decorate --all --graph”SEE A DIFF:

git diff [<from commit>] <to commit>MERGE INTO A BRANCH:

git checkout <branch to merge into>git merge <branch to merge>REBASE A BRANCH:

git rebase <new base> [<branch to rebase>]UNDO YOUR MISTAKES:

git refloggit reset --hard <commit> (escape { with backtick in powershell: git reset –hard @HEAD`{1`})

THESE ARE MORE INTERESTING THAN USEFUL:

git hash-object <file>git cat-file –p <sha>

@jamesw0rld