Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

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

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.

Comments
  1. toothrot says:

    My favorites for big projects (missing from here):

    To find those pesky build-breaking commits:
    git bisect start HEAD HEAD@{one.day.ago}
    git bisect run rake

    Notably, REF@{one.day.ago} being very awesome.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *