Railsconf: Smacking Git Around – Advanced Git Tricks Scott Chacon (GitHub)

May 6, 2009 Pivotal Labs

Presentation

Cheat Sheet

Range selection:

  • Full SHA1
  • Partial SHA1 – at least 4 characters and unique
  • Branch, remote or tag name
  • Caret parent: master^^ (2nd parent of master)
  • Tilde spec: master~2 (2nd parent of master)
  • Combination: master~2^2
  • Blob spec: default:path/to/file
  • Relative spec: master@{yesterday} (relative to your machine)
  • master@{5} the 5th last value of master (locally)
  • [old]..[new] everything reacable from new but not from old
  • jes/master..master
  • jes/master..c36ae

Log usage:

  • git log origin/master.. or origin/master..HEAD only the commits that are going to go upstream
  • git log ..origin/master or HEAD..origin/master everything that origin/master has that you do not
  • git log master –not origin/master
  • git log master –not origin/master
  • git log –graph gives an ascii graph of listory

Diff:

  • git diff HEAD…topic go backto a common ancestor before diffing – gives better results`
  • git commit –ammend modify the last commit

Rebasing:

  • Replay the changes in my branch on top of another branch.
  • rebase –onto use for transplating a topic branch.
  • To transplant some of a topic branch, create a new branch to refer to the part you don’t want then do a rebase –onto.
  • git rebase -i <ref> interactvely pick/redorder/squash by editing a list/script.
  • DO NOT rebase using any commits you have already pushed upstream.

Filter Rebranch:

  • git filter-branch –tree-filter ‘rm -f filename’ HEAD Remove all instances of a file from every commit.

Subtree merging:

  • Alternative to submodules. Looks way complex. Tim Dysinger wrote rake tasks go do this. Google it.

Patch Staging

  • git add -p patch staging – interactively stage only some hunks of a file.

Debugging

  • Annotation: git blame
  • git blame -C <file> even if your like was moved from another file, produce a blame report for it.
  • git bisect

    git bisect start
    git bisect bad (Assumes HEAD)
    git bisect good 3acb4

    takes range you just specified, picks the middle commit nad checks it out, you call it good or bad, wash rince repeat.

    git bisect reset # when you are done.

Customization

  • git config –global help.autocorrect 1 – Stop git com complaining.
  • git config –global color.ui auto
  • Configure external merge tool.
  • .gitattributes for this class of files that match this pattern, treat them differently: e.g. diff binary files echo ‘*.png diff=exif’ >> .gitattributes and add a gitconfig line describing the exif diff strategy.

About the Author

Biography

Previous
Railsconf: Cucumber – Aslak Hellesoy
Railsconf: Cucumber – Aslak Hellesoy

Most of this talk was a basic Cucumber primer. However these things were new to me: Multi-line arguments ...

Next
Railsconf: Building a Mini-Google in Ruby – Ilya Grigorik
Railsconf: Building a Mini-Google in Ruby – Ilya Grigorik

Ilya's slides are already on the web. A few random notes: In 1994-1995 term frequency was state of the ar...