Wednesday, December 30, 2009

Make Amends with Git

I've always been a fan of small, concise commits. I strive to make my commits as small and concise as possible.

However I often fail... Very often I commit and... discover that I yet again forgot to fix a typo. Or remove a blank line. Nothing major. But it's pretty annoying to have every other commit log reading 'fixed typo' or 'formatted code'.

With Git, I don't have this problem anymore.

If I want to add some changes to the last commit, I simply type:
git add somefile
git commit --amend

Tada! I just modified my last commit to include new changes.

The other option I like to use from time to time is the rebase interactive mode. I use it to merge various commits into one. It has more powerful uses (like removing commits entirely) but I never used these (yet).
git rebase -i origin

Of course  you have to use these commits before pushing anything to a remote repository. 


With these these two commands, I can keep my commit log a little bit cleaner.

No comments:

Post a Comment