Upgrade to Pro — share decks privately, control downloads, hide ads and more …

git - the stupid content tracker

git - the stupid content tracker

This talk was presented to OTB on March 9th 2012. Check github.com/seenmyfate/git-presentation-demo for some source code goodness

Tom Clements

March 09, 2012
Tweet

More Decks by Tom Clements

Other Decks in Programming

Transcript

  1. Things in git Things stored in git are objects Those

    objects have an ID That ID is a cryptographic hash of the components of that object
  2. Things stored in git are objects blob - used to

    store file data tree - like a directory, references trees/blobs commit - points to a single tree
  3. That ID is a hash of the components $ git

    ls-tree dca0d08 100644 blob 24c681c .gitignore 100644 blob 3f00574 .rvmrc 100644 blob 293cb17 Gemfile 100644 blob 8e4f0f0 Gemfile.lock $ git show 3f00574 rvm use 1.9.3@gitdemo --create
  4. If all these things are true we're on our local

    master branch at commit 9ad544f we've pushed
  5. so onto gitiquette Know what you're committing Know what you're

    not committing Commit with a well formed message Know what you're pulling Resolve conflicts with care
  6. Know what you're committing $ git add --all app $

    git add --all lib/file.rb $ git add lib/file.rb -p
  7. Know what you're not committing $ git stash $ git

    stash save "wip" $ git stash list $ git stash apply stash@{0}
  8. Commit with a well formed message $ git config --global

    core.editor emacs $ git commit Follow @tpope's advice
  9. Rewrite history Commit with a well formed message $ git

    commit -m "RT1234..." ..realise you forgot something.. $ git commit -m "fixup! RT1234" Then autosquash your last 2 commits $ git rebase --autosquash HEAD~2
  10. use the force $ git push origin +my_branch $ git

    push origin my_branch --force
  11. Know what you're pulling $ git log origin/master -p $

    git fetch origin $ git whatchanged $ git log --graph --oneline
  12. Rebase Workflow never commit directly to master update master using

    git pull origin master rebase your feature branch from your local master
  13. Rebase if I branch when master is at B 1---2---3

    #my_branch / A---B #master and our branches diverge 1---2---3 #my_branch / A---B--C--D--E--F #master
  14. Rebase Rebase replays my changes onto current master 1---2---3 #my_branch

    / A---B--C--D--E--F #master So it's as if I branched today No merge bubble No messy history
  15. My workflow Never work or commit directly to master use

    branches for everything rebase feature branches from master squash working commits to one single feature commit merge this feature into master via a release branch
  16. For example $ git pull origin master $ git checkout

    -b feature/my_branch ..work / commit.. $ git checkout master $ git fetch origin $ git pull origin master $ git checkout feature/my_branch $ git rebase -i master ..work / commit..
  17. only ever push one branch $ git push origin will

    push all changes on the local branches that have matching remote branches at origin $ git push origin my_branch
  18. ~/.zshrc function current_branch() { ref=$(git symbolic-ref HEAD 2> /dev/null) ||

    return echo ${ref#refs/heads/} } alias ggpush='git push origin $(current_branch)' alias ggpull='git pull origin $(current_branch)'
  19. one liners $ git show-ref --heads see if your branches

    are up to date $ git log --pretty=oneline -S'massive_fail' search for when someone added the term to the repo $ git blame test/functional/posts_controller_test.rb the precursor to git punch $ git grep -c -n <term/regexp> $(git rev-list --all) search historically for a term or rgexp $ git log --graph historic graph goodness $ git log --all -M -C --name-only --format='format:' \ "$@" | sort | grep -v '^$' | uniq -c | sort | \ awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}' churn
  20. config $ git config --global help.autocorrect 1 $ git commint

    WARNING: You called a Git command named 'commint', which does not exist. Continuing under the assumption that you meant 'commit'
  21. Bisect $ git bisect start $ git bisect good 85d026e

    $ git bisect bad 6a24cd3 $ git bisect run rake $ git show $ git bisect reset