YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Git: Beyond the Basics

gitbeyondthebasics

Thursday, August 2, 12

Page 2: Git: Beyond the Basics

John Bohn@jjbohn

Thursday, August 2, 12

Page 3: Git: Beyond the Basics

Developer at OpenSkycurated social commerce

Thursday, August 2, 12

Page 4: Git: Beyond the Basics

gitwhat is

Thursday, August 2, 12

Page 5: Git: Beyond the Basics

git is fast and lightweightfree/open sourcedistributedcrazy simple

Thursday, August 2, 12

Page 6: Git: Beyond the Basics

initbranchaddcommitmerge

Thursday, August 2, 12

Page 7: Git: Beyond the Basics

Almost any VCS works does this(more or less)

What is special about git?

Thursday, August 2, 12

Page 8: Git: Beyond the Basics

Interactivity

Thursday, August 2, 12

Page 9: Git: Beyond the Basics

git add --patchgit add --interactive

Thursday, August 2, 12

Page 10: Git: Beyond the Basics

Arduino Example

Thursday, August 2, 12

Page 11: Git: Beyond the Basics

Change Blink

Thursday, August 2, 12

Page 12: Git: Beyond the Basics

Change Blink

- Two logical changes- Don’t want to bother undoing one- Can’t git add . or git add [file]

Thursday, August 2, 12

Page 13: Git: Beyond the Basics

git add --patch

Thursday, August 2, 12

Page 14: Git: Beyond the Basics

git add --patch

Thursday, August 2, 12

Page 15: Git: Beyond the Basics

git add --patch

Thursday, August 2, 12

Page 16: Git: Beyond the Basics

git add --patchCommit the change

Thursday, August 2, 12

Page 17: Git: Beyond the Basics

git add --patchStage other changes

Diff is now empty (everything is staged or commited)Thursday, August 2, 12

Page 18: Git: Beyond the Basics

git stash

Thursday, August 2, 12

Page 19: Git: Beyond the Basics

is super boring

Thursday, August 2, 12

Page 20: Git: Beyond the Basics

until you throw some flags at it...

Thursday, August 2, 12

Page 21: Git: Beyond the Basics

git stash --no-keep-indexgit stash --keep-index

git stash --patchgit stash --include-untracked

My Favorites

Thursday, August 2, 12

Page 22: Git: Beyond the Basics

Finding these commands is just a matter of digging

Thursday, August 2, 12

Page 23: Git: Beyond the Basics

git anything --help

Thursday, August 2, 12

Page 24: Git: Beyond the Basics

git resetis not

git revert

Thursday, August 2, 12

Page 25: Git: Beyond the Basics

git reset --soft [sha]git reset --hard [sha]git reset --mixed [sha]

Thursday, August 2, 12

Page 26: Git: Beyond the Basics

You can also:git reset --patch(but not with those modes)

Thursday, August 2, 12

Page 27: Git: Beyond the Basics

Bisectingaka: Finding a commit

that screwed things up.

Thursday, August 2, 12

Page 28: Git: Beyond the Basics

Bisecting

Thursday, August 2, 12

Page 29: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43

6 Commits - One BugWe know that 7b35b is goodWe know that cfc332 is badBut we have no idea where the bug was introduced

cfc332

Thursday, August 2, 12

Page 30: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43

Tell git what is known good and bad

cfc332good bad

Thursday, August 2, 12

Page 31: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43 cfc332good bad

Thursday, August 2, 12

Page 32: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43 cfc332good badgood

Thursday, August 2, 12

Page 33: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood

Thursday, August 2, 12

Page 34: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood

2ab1f is most likely good because the commit after it is

Thursday, August 2, 12

Page 35: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood bad

Thursday, August 2, 12

Page 36: Git: Beyond the Basics

Bisecting

7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood badbad

Thursday, August 2, 12

Page 37: Git: Beyond the Basics

Recovering lost commits

Thursday, August 2, 12

Page 38: Git: Beyond the Basics

git reflog

Thursday, August 2, 12

Page 39: Git: Beyond the Basics

git reflog

Technically shows any action where the tip of a branch is modified

git reflog --allshows stashes, bisects, etc.

Thursday, August 2, 12

Page 40: Git: Beyond the Basics

Recovery

Let’s say I reset --hard and wiped out the commit that changed my LED to pin 10Use combination of reflog and cherry-pick to get it back

Thursday, August 2, 12

Page 41: Git: Beyond the Basics

Recovery

Found it! 3ecdba3

Thursday, August 2, 12

Page 42: Git: Beyond the Basics

RecoveryDouble check that 3ecdba3 is really the commit we want

git diff 3ecdba3^.. 3ecdba3

Shows me the difference between the commit I wantto cherry pick and the commit prior.

Thursday, August 2, 12

Page 43: Git: Beyond the Basics

git cherry-pickNow cherry pick 3ecdba3 into our working tree

Note: the sha has changed because this commit now hasa different parent than it did when it was recorded into the reflog

Thursday, August 2, 12

Page 44: Git: Beyond the Basics

RecoveryCheckout the reflog again to see the cherry-pick

Thursday, August 2, 12

Page 45: Git: Beyond the Basics

Interactive RebasingChanging the past one commit at a time

Thursday, August 2, 12

Page 46: Git: Beyond the Basics

git rebase -i [commit]

Thursday, August 2, 12

Page 47: Git: Beyond the Basics

git rebase -i [commit]

Thursday, August 2, 12

Page 48: Git: Beyond the Basics

git rebase -i [commit]

Thursday, August 2, 12

Page 49: Git: Beyond the Basics

git rebase -i [commit]

Thursday, August 2, 12

Page 50: Git: Beyond the Basics

Interactive rebase

Thursday, August 2, 12

Page 51: Git: Beyond the Basics

git internalsThe plumbing and the porcelain

Thursday, August 2, 12

Page 52: Git: Beyond the Basics

git internalsgit stores snapshots, not differencesStoring differences is slow and inflexible

CVS/Subversion git

Thursday, August 2, 12

Page 53: Git: Beyond the Basics

git internalsgit stores snapshots, not differencesStoring differences is slow and inflexible

CVS/Subversion git

Thursday, August 2, 12

Page 54: Git: Beyond the Basics

git internals

What does a commit look like?

Thursday, August 2, 12

Page 55: Git: Beyond the Basics

git internals

Let’s investigate a repo

Sorry for the bad “investigation” image ;-)

Thursday, August 2, 12

Page 56: Git: Beyond the Basics

Thanks!Come work with me at OpenSky!

We’re Hiring

Thursday, August 2, 12


Related Documents