2010-08-30

Committing part of a file

A fantastic feature of git I only found a few days ago is committing just part of a file. Usually I have the foresight to use git stash but sometimes that doesn't occur or it's not practical for whatever reason, such as only realizing after the edits that the changes in a particular file should be two commits rather than one.

When this happens you can interactively choose which parts of the changes to stage for committing. To do that:

git add -p file.php

Git then shows each part of the patch in sequence, asking what you want to do with them. You can stage the change, not stage it, split it into smaller chunks, decide later or even edit the patch manually.

No comments:

Post a Comment