1

It is established that each individual Git commit should be a single logical change. It is also established that this production process is often messy (see sausage-making) and should not be hidden away - Seth Robertson advocates "Commit often, perfect later".

I find that at some point, either at the end of a project or at the end of a series of related commits, I need to tidy my code, especially if I have been engrossed in a problem and working quickly. By tidy I don't mean logical changes that affect the actual workings of the program, but rather things like:

  • Clarifying comments
  • Changing the order of functions to improve readability
  • Correcting indents/whitespace
  • Deleting old tests like // console.log(variables)

My question is then: is it best practice to save these 'cosmetic' changes in a separate individual commit? (And if not how should they be committed?)

Note that I'm not inviting opinion on this. Surely there is an established best-practice; the article above emphasises enforcing standards, so it's important to know what those standards are.

As well as Seth Robertson's article I've read the following existing questions, but I can't find my question addressed anywhere:

Community
  • 1
  • 1
andydavies
  • 3,081
  • 4
  • 29
  • 35
  • commit cosmetic changes separately. It helps in problem isolation later, since you can usually skip the entire cosmetic-changes-only commit, when looking for a bug. – Gregg May 18 '16 at 17:32
  • http://stackoverflow.com/a/19656336/6194839 I found this while looking through your links, as I agree that there should be a standard. Here is what I want to highlight from that link: ():
    Designate a of your commit as cosmetic.
    – Bryce Drew May 18 '16 at 17:37
  • 1
    @BryceDrew I see what you mean. Your comment prompted me to find other examples of reputable style guides that list various commit 'types' and a recommended prefix to the commit messages. For example https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages (prefix 'art:' for style changes) and https://udacity.github.io/git-styleguide/ (prefix 'style:'). This tends to suggest that there IS a convention of style changes being a valid commit. I'd add these references as an answer but unfortunately the question is on hold. – andydavies May 20 '16 at 13:11

1 Answers1

1

Yes, cosmetic changes should be separate. They are a logical change separate from the functional changes. Also, it makes it easier to review the functional changes.

FelipeC
  • 9,123
  • 4
  • 44
  • 38