litany against fear

coding with spice ¤ by nick quaranto

RailsConf 2009 Smacking Git Around

published 05 May 2009

This is part of my series of notes on RailsConf 2009. Check them all out here.

This talk is definitely for those who use Git daily. Going through a whirlwind introduction to Git in under a minute.

Learning about Revision Selection first. It’s an alternate way to referring to ranges of commits. There’s tons of ways to refer to objects in Git:

  • SHA1
  • Partial SHA1 (at least 4 chars and unique in the git datastore)
  • Branch, remote, tag names
  • Caret Parent (master^2)
  • Numbered Parent (master~2)
  • Blob Spec (master:path/to/file)
  • Relative Specs
  • Ranges [old]..[new] that are reachable. Really useful to see what hasn’t been pushed yet or what’s upstream.

What am I going to push? git log origin/master .. Lots of visual examples that would be way to difficult to show in text only. To see what’s in a branch and not in another: git log master --not origin/master or git log master ^origin/master

Showing off how Git doesn’t really treat git diff correctly. Using the ... syntax allows you to check differences when you want to merge. So usually: git diff HEAD...topic

Changing previous commits with git commit --amend: first off: you can modify commit messages, and any staged files will get added in.

Doesn’t seem like many people understand how git rebase works. Going through how the rebase process actually does its magic. Showing off a great example of using git rebase --onto. It’s used to transplant entire sections of commits cleanly. You can use branches as a lightweight way to refer to commits during a rebase.

Running through a git rebase -i. It actually loads a script that’s executed in reverse order. Lots of fun stuff here: squshing, picking, reordering, and so on.

Showing off git filter-branch for rewriting the entire history.

There’s an alternative to submodules: sub-tree merging. This involves adding a remote for a project that isn’t a direct clone. You can also use git read-tree to pull out specific trees from other remotes and merge them in. git merge has a ton of crazy options: -s subtree --no-commit --squash whoa.

It’s possible to stage changes interactively with git add -p. There’s also git blame, and it’s -C option. This option allows you to see code blocks that were moved in from other files so you can see when they were originally modified.

Going through git bisect and how you can use it to find bugs.

The git config is full of awesome options (enable with git config --global)

  • help.autocorrect 1: Git will autocomplete commands that you mistype or didn’t finish.
  • color.ui auto: Turn on colors when in the terminal only
  • Custom merge tools: plenty of ways to configure your own. Check the cheatsheet.

Lots of stuff that can be done with .gitattributes. Diffing binary files is one option, which Git usually barfs with. You can tell Git how to diff a binary file. Showing how to set this up. The end result is awesome, exiftool can show you how resolutions changed, etc. This also works on Word Documents!

Filters are pretty crazy too. The process is basically this: a smudge script processes files during checkout, and a clean filter runs on files when committed. This can be done to implement a $Date$ RCS style variable.

Scott also uploaded the slides and a cheatsheet so you can see everything that was covered.



code (2) gaming (3) git (9) internet (5) prorubyconf (25) railsconf (17) ruby (10) windows (3)