If there is a reason for it being done 'this way' that is not obvious then there should be a comment in the code explaining the thought process.
A commit won't really help you as much there as future refactoring might obscure the original commit that added the code.
That being said, if there's some complexity in what is being solved I will usually add a very quick description of it in the commit message "Used XYZ algorithm to implement ABC due to it being faster/cleaner. See: ticket/wiki/documentation".