Having grown up with CVS then moved on to svn, I find git amazingly powerful. However, I don't use it enough to learn some of the more powerful features. This is just a post to document a couple of useful things I learned recently.

I was working on a project on github, adding a missing command-line option. But, while editing, I got carried away and made a load of additional trivial changes, cleaning up the man page text, making capitalisation consistent, etc. All good stuff, but I didn't want to commit both sets of changes in the same commit.

What I needed to do was to select which changes to commit. The command to do that is:

git add --patch

To show the changes that have been added to the staging area, ie. those that will be commited:

git diff --cached

If you mistakenly add a change and want to remove it from the staging area:

git reset --patch

Finally, commit the change:

git commit

Optionally, push the change back to github:

git push origin master

Nifty stuff.

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required