Tuesday, December 15, 2009

git-add --patch

I just recently found Ryan Tomayko's essay about using git-add --patch.

I love the essay; it's quite well written.

He makes two interesting and inter-related points in the essay:

  • git-add --patch allows you to solve a problem in a (fairly) easy way which is extremely hard to solve using other source code control tools and methodologies.

  • The flexibility and power of Git is integral to its philosophy, and you won't understand Git until you understand this philosophy.



From the essay:

The thing about Git is that it's oddly liberal with how and when you use it. Version control systems have traditionally required a lot of up-front planning followed by constant interaction to get changes to the right place at the right time and in the right order.
...
Git is quite different in this regard.
...
When I'm coding, I'm coding. Period. Version control -- out of my head. When I feel the need to organize code into logical pieces and write about it, I switch into version control mode and go at it.


It's a very interesting essay, both the concrete parts about how to use the low-level Git tools to accomplish some very specific tests, as well as the more abstract sections about why the author feels that this tool supports his own personal software development process more effectively.

I think that there isn't enough discussion about the role of tools in the development process, and about how tools influence and guide the success or failure of a particular process. One of my favorite articles in this respect is Martin Fowler's essay on Continuous Integration. I'm pleased whenever I find articles discussing the interaction of tools and process, since more discussion can only help improve the situation with respect to software development processes and tools.

2 comments:

  1. So git helps me check in a version of code that has never even compiled.

    ReplyDelete
  2. ^ You could if you wanted to, but with a few command flags you can easily build the code you are about to commit.

    From the git stash man page

    # ... hack hack hack ...
    $ git add --patch foo # add just first part to the index
    $ git stash save --keep-index # save all other changes to the stash
    $ edit/build/test first part
    $ git commit -m 'First part' # commit fully tested change
    $ git stash pop # prepare to work on all other changes
    # ... repeat above five steps until one commit remains ...
    $ edit/build/test remaining parts
    $ git commit foo -m 'Remaining parts'

    ReplyDelete