Managing aesthetic code changes in git

Posted by Ollie Saunders on Stack Overflow See other posts from Stack Overflow or by Ollie Saunders
Published on 2009-09-24T11:27:46Z Indexed on 2010/04/16 16:03 UTC
Read the original article Hit count: 279

I find that I make a lot of small changes to my source code, often things that have almost no functional effect. For example:

  • Refining or correcting comments.
  • Moving function definitions within a class for a more natural reading order.
  • Spacing and lining up some declarations for readability.
  • Collapsing something using multiple lines on to one.
  • Removing an old piece of commented-out code.
  • Correcting some inconsistent whitespace.

I guess I have a formidable attention to detail in my code. But the problem is I don't know what to do about these changes and they make it difficult to switch between branches etc. in git. I find myself not knowing whether to commit the minor changes, stash them, or put them in a separate branch of little tweaks and merge that in later. None those options seems ideal.

The main problem is that these sort of changes are unpredictable. If I was to commit these there would be so many commits with the message "Minor code aesthetic change.", because, the second I make such a commit I notice another similar issue. What should I do when I make a minor change, a significant change, and then another minor change? I'd like to merge the three minor changes into one commit. It's also annoying seeing files as modified in git status when the change barely warrants my attention. I know about git commit --amend but I also know that's bad practice as it makes my repo inconsistent with remotes.

© Stack Overflow or respective owner

Related posts about version-control

Related posts about best-practices