Skip to content

Instantly share code, notes, and snippets.

@webmat
Created May 6, 2014 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmat/4b8a65cf865fd69fafc8 to your computer and use it in GitHub Desktop.
Save webmat/4b8a65cf865fd69fafc8 to your computer and use it in GitHub Desktop.
Git lightning talk
Understanding the concepts
- The Git Parable, but Tom Preston-Werner
http://tom.preston-werner.com/2009/05/19/the-git-parable.html
- git is a bucket of commits
- most commits have one parent, and a blob
- some commits have 2 parents (merges)
- some commits have 1 parents (first commit!)
- refs
- branches: pointers to a commit - moves over time
- tags: pointers to a commit - does not move
finding unmerged commits
git branch -a --no-merged
git branch -a --merged
finding lost commits
1) don't get lost
a) where are you?
zshrc with oh-my-zsh
plugins=(git ...)
bash_profile:
source /usr/local/etc/bash_completion.d/git-prompt.sh
source /usr/local/etc/bash_completion.d/git-completion.bash
PS1='\n\A \u@\h \W$(__git_ps1 " (%s)")\$ '
b) visualize it
GitX (forked): http://rowanj.github.io/gitx/
GitHub's client, gitk, etc
2) actually find the commit
- git reflog (recent HEADs)
- git fsck (lower level)
git show --no-color 926eb3759b1fbce3afa2ee6fbd3917f57c9460f1 | mate
3) recover the commit
- git cherry-pick [ref]
re-applies the [ref] commit in your current branch (it's a new commit since it has a new parent)
- git diff --no-color [ref] > ../ohai.diff
you can send that around before applying it
- git merge / rebase
in the simple scenarios
finding the introduction of a bug in a long timeline
Git bisect does a binary search through between two commits you specify
gotcha: if the command you run is in version control, the file may change as well from one commit to another. If that's the case, extract the file, or reproduce the bug in a simpler manner outside of git, so it's consistent across checkouts.
Commands:
git bisect start # puts git in "bisect" mode. You can't commit or do anything else until "git bisect reset"
git bisect good [commit id] # what's the last known good commit
git bisect bad [commit id] # what's the first commit where you
git bisect run [command] # must return non-zero when the bug is present
# Tweet about using git bisect while git does the heavy lifting.
# ... once found, git displays a recap
git bisect reset # get back to normal state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment