git: beyond the basics
DESCRIPTION
Git Beyond the Basics with John Bohn One thing that makes git a great version control systems is its low barrier to entry, but there's so much more to learn. We'll start with a very brief intro to git and quickly move onto some more fun and advanced topics such as recovering lost commits, rebasing, bisecting, bookmarking and more. Come learn some valuable tips and tricks that are sure to same you time and headaches. A second generation developer working at OpenSky, John Bohn is an open source contributor and advocate of anything that gets the job done better and faster.TRANSCRIPT
gitbeyondthebasics
Thursday, August 2, 12
John Bohn@jjbohn
Thursday, August 2, 12
Developer at OpenSkycurated social commerce
Thursday, August 2, 12
gitwhat is
Thursday, August 2, 12
git is fast and lightweightfree/open sourcedistributedcrazy simple
Thursday, August 2, 12
initbranchaddcommitmerge
Thursday, August 2, 12
Almost any VCS works does this(more or less)
What is special about git?
Thursday, August 2, 12
Interactivity
Thursday, August 2, 12
git add --patchgit add --interactive
Thursday, August 2, 12
Arduino Example
Thursday, August 2, 12
Change Blink
Thursday, August 2, 12
Change Blink
- Two logical changes- Don’t want to bother undoing one- Can’t git add . or git add [file]
Thursday, August 2, 12
git add --patch
Thursday, August 2, 12
git add --patch
Thursday, August 2, 12
git add --patch
Thursday, August 2, 12
git add --patchCommit the change
Thursday, August 2, 12
git add --patchStage other changes
Diff is now empty (everything is staged or commited)Thursday, August 2, 12
git stash
Thursday, August 2, 12
is super boring
Thursday, August 2, 12
until you throw some flags at it...
Thursday, August 2, 12
git stash --no-keep-indexgit stash --keep-index
git stash --patchgit stash --include-untracked
My Favorites
Thursday, August 2, 12
Finding these commands is just a matter of digging
Thursday, August 2, 12
git anything --help
Thursday, August 2, 12
git resetis not
git revert
Thursday, August 2, 12
git reset --soft [sha]git reset --hard [sha]git reset --mixed [sha]
Thursday, August 2, 12
You can also:git reset --patch(but not with those modes)
Thursday, August 2, 12
Bisectingaka: Finding a commit
that screwed things up.
Thursday, August 2, 12
Bisecting
Thursday, August 2, 12
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
Bisecting
7b35b 912969680d2ab1f c6d43
Tell git what is known good and bad
cfc332good bad
Thursday, August 2, 12
Bisecting
7b35b 912969680d2ab1f c6d43 cfc332good bad
Thursday, August 2, 12
Bisecting
7b35b 912969680d2ab1f c6d43 cfc332good badgood
Thursday, August 2, 12
Bisecting
7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood
Thursday, August 2, 12
Bisecting
7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood
2ab1f is most likely good because the commit after it is
Thursday, August 2, 12
Bisecting
7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood bad
Thursday, August 2, 12
Bisecting
7b35b 912969680d2ab1f c6d43 cfc332good badgoodgood badbad
Thursday, August 2, 12
Recovering lost commits
Thursday, August 2, 12
git reflog
Thursday, August 2, 12
git reflog
Technically shows any action where the tip of a branch is modified
git reflog --allshows stashes, bisects, etc.
Thursday, August 2, 12
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
Recovery
Found it! 3ecdba3
Thursday, August 2, 12
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
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
RecoveryCheckout the reflog again to see the cherry-pick
Thursday, August 2, 12
Interactive RebasingChanging the past one commit at a time
Thursday, August 2, 12
git rebase -i [commit]
Thursday, August 2, 12
git rebase -i [commit]
Thursday, August 2, 12
git rebase -i [commit]
Thursday, August 2, 12
git rebase -i [commit]
Thursday, August 2, 12
Interactive rebase
Thursday, August 2, 12
git internalsThe plumbing and the porcelain
Thursday, August 2, 12
git internalsgit stores snapshots, not differencesStoring differences is slow and inflexible
CVS/Subversion git
Thursday, August 2, 12
git internalsgit stores snapshots, not differencesStoring differences is slow and inflexible
CVS/Subversion git
Thursday, August 2, 12
git internals
What does a commit look like?
Thursday, August 2, 12
git internals
Let’s investigate a repo
Sorry for the bad “investigation” image ;-)
Thursday, August 2, 12
Thanks!Come work with me at OpenSky!
We’re Hiring
Thursday, August 2, 12