'Should I write the reasoning in the commit message or an inline comment?

I've often heard that the commit message should describe why I'm making these changes. And I think I agree with that. However, I've also often heard that inline comments (i.e. comments in the source code) should tell why the code works in this particular way instead of what it does.

So, when should I put the reasoning in the commit message, and when should it be written in an inline comment? Is there some rule-of-thumb or best practice that can be applied?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source