My Favourite Git Commit
fatbusinessman.com
fatbusinessman.com
Add = Create a capability e.g. feature, test, dependency.
Cut = Remove a capability e.g. feature, test, dependency.
Fix = Fix an issue e.g. bug, typo, accident, misstatement.
Bump = Increase the version of something e.g. dependency.
Make = Change the build process, or tooling, or infra.
Start = Begin doing something; e.g. create a feature flag.
Stop = End doing something; e.g. remove a feature flag.
Refactor = A code change that MUST be just a refactoring.
Reformat = Refactor of formatting, e.g. omit whitespace.
Optimize = Refactor of performance, e.g. speed up code.
Document = Refactor of documentation, e.g. help files.The whole thing should be width limited to 80 or 100 characters.
And the subject line should complete the sentence "If this commit is applied, it will...". It should start with a capital letter, then move to lowercase, and necessarily will start with a verb.
A good commit message isn't about convention, and no convention makes a commit message good.
When I review a commit, I need only the information I won't get from the diff that I need to understand the context and the behavior.
My brainpower is a limited resource and extra noise in my signal is extra work.
I'm totally here for `ISSUE_123456 fixes defect` and `wip` are insufficient, but I'm not writing a code blog post in there.
It's not a hard and fast rule and it's ok to ignore it when it makes sense. But we also don't mind if your commit message takes longer to write than the code took to change and debug.
A lot of context is assumed in commits, and almost all of it is temporal. Capturing as much of that as possible pays off down the line.
Commit in the article is a good example where the context explains much more than the change.
(On the flip side, the pay off has an expiry date so I'm not extremely fussed when people lax, but it's still good to check in basic assumptions whith your code)
I notice no hindrance on my speed because I write good commit messages, and always value them when I one back to them.
I kind of do it like this. Others use subjects that complete the sentence "This commit...", so their subjects will start with "adds", "fixes", etc. Though that adds one or two extra characters!
[1]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153
I.e. Love using husky to enforce code conventions through linters...
Only issue is it would be hard to completely enforce in code and obviously require some review but still nice
The other thing I do is add a "MODULE:" prefix to my commit message. It makes them way more readable. Lots of other people do this too; you can see this in Redis, Linux, and Go codebases, for example.
So your message might look like "router: add support for path vars". Much easier to read than "Add support for path vars to router"
I don't stick to it as a rule but if it's clearly grouped in some way it gives people in the wider org a high level fyi about the area of code you're messing with.
Makes it easy to jump over the commit when bisecting for regressions or hastily looking for the buggy commit to revert.
Originally I suggested we put the JIRA number/link in the commit body, but then I learned about git-notes to add metadata to commits and now I kinda want to do this with the semantic labels suggested by the thread OP, too (I currently use the schema suggested at https://seesparkbox.com/foundry/semantic_commit_messages).
The branch is called feature/<Ticket ID>-<short-description>
The commits contain usual commit messages. When merging, changes are quashed. The final commit message is similar to the branch name and includes the ticket and a short description, which is similar to the mentioned pattern (bump/add/change/whatever).
Add = Create a capability e.g. feature, test, dependency.
Cut = Remove a capability e.g. feature, test, dependency.
Fix = Fix an issue e.g. bug, typo, accident, misstatement.
Bump = Increase the version of something e.g. dependency.
Make = Change the build process, or tooling, or infra.
Start = Begin doing something; e.g. create a feature flag.
Stop = End doing something; e.g. remove a feature flag.
Refactor = A code change that MUST be just a refactoring.
Reformat = Refactor of formatting, e.g. omit whitespace.
Optimize = Refactor of performance, e.g. speed up code.
Document = Refactor of documentation, e.g. help files.
Is it a vocab consistency thing?
I see pretty consistent vocab used across orgs anyway, so given there is shardd domain knowledge / language at play, im not sure what the goal for standardization is?
Don't take this the wrong way, I use a lot of these when appropriate, but I don't think I could agree that refactoring must be just a refactor, and I don't think I want to limit anyone's commits to this list of change types either.
Forcing changes into these words means a lot of stuff is pointlessly bucketed when more appropriate wording could be used.
Say I want to push a commit "prioritise shipping route a over route b".
So I have to put it under start? Optimise? Fix? Why? Prioritise is the right word, why not just use that? Why play mind games when we have a whole dictionary to draw from?
- Change: change functionality or behavior.
- Cleanup: more than formatting, less than refactoring. No functional changes.
- Rename: refactoring that changes a name but does nothing else.
- Extract: refactoring that creates a new module or class by moving code out of an existing module or class.
https://www.mercurial-scm.org/repo/hg/rev/3764330f76a6
https://www.mercurial-scm.org/repo/hg/rev/93486cc46125
https://www.mercurial-scm.org/repo/hg/rev/b7a966ce89ed
https://www.mercurial-scm.org/repo/hg/rev/4a0d0616c47d (all modesty aside)
Long commit messages aren’t that atypical. Have a stroll through the logs:
https://www.mercurial-scm.org/repo/hg/log?style=gitweb
Mercurial inherited this style of commit messages from Linux email-based code review (the Mercurial originator was a kernel hacker), because in that workflow your commit messages are kind of a persuasive essay for why your commit should be accepted. I believe that writing commit messages with that kind of goal in mind, thinking “why should you take this commit?” is a good motivator for writing something good and useful.
[1] https://github.com/mpv-player/mpv/commit/1e70e82baa9193f6f02...
> All in all, I believe this proves that software developers as a whole and as a culture produce worse results than drug addicted butt fucked monkeys randomly hacking on typewriters while inhaling the fumes of a radioactive dumpster fire fueled by chinese platsic toys for children and Elton John/Justin Bieber crossover CDs for all eternity.
I also nominate this commit.
> like Shift JIS (sometimes called SHIT JIZZ)
Back then when I was working for a Japanese outsourced project, the code won't compile unless the computer's locale was set to Japanese because the C code had comments in Shift JIS.
Even the papers are snarky. [2]
> Well the other people heavily funding vision research are the military and they’ve never done anything horrible like killing lots of people with new technology oh wait.....
> The author is funded by the Office of Naval Research and Google.
He's being funded for this. This is fantastic.
https://pjreddie.com/darknet/yolo/
https://pjreddie.com/static/Redmon%20Resume.pdf
This is the kind of guy I'd love to hang out with.
Ultimately, it boils down to people's gut feelings, which is so disgustingly random.
At a certain level, it's boring to just be good. The interesting challenge becomes to stay good while being silly as fuck.
And that's why I'm serious and professional.
> I have a lot of hope that most of the people using computer vision are just doing happy, good stuff with it, like [...] tracking their cat as it wanders around their house
And then suddenly realized I've wanted to do exactly that for a long time. Well... specifically install a camera that can detect my cat on the counter (and not my hands doing stuff) and sound an alarm/puff air to get him off.
Could this work for that? I think it could! I know my winter project...
[1] http://quinndunki.com/blondihacks/?p=3023 [2] https://news.ycombinator.com/item?id=13230904
After many months, my cat learned to stand on top of the lid and use both paws to rotate the switch forward until the lid popped open.
This blew my mind. The switch was separated from the lid. I could imagine the cat attacking the lid itself, but this separate mechanism, requiring a motion completely distinct from the motion of an opening lid, and requiring patience without instantaneous reward or even evidence that it was going to work.... I just couldn't believe it.
One example: https://sep.yimg.com/ay/entirelypets/kyjen-dog-games-slo-bow...
I love seeing a section like this when reviewing a paper. I really wish more authors would include one. (Goodness knows I've chased down enough dead-ends in some of my own research efforts.)
What's funny, though, the paper (written in a pretty much the same "fuck you" manner) is much more readable and informative than the average. Which says a lot about science papers out there.
* https://www.graphviz.org/gallery/
* https://en.wikipedia.org/wiki/DOT_(graph_description_languag...
It does go off on a few tangents, but it's an interesting read.
You weren't kidding about the tangents.
"When you omit courtesy you're throwing sand in the gears of a machine that doesn't work too well in the first place."
~Heinlein (I'm paraphrasing.)
There's no glory in being a boor, and no shame in being courteous.
None of this is news: https://en.wikipedia.org/wiki/Etiquette#History
A fool never learns,
A man learns from his mistakes,
A wise man learns from the mistakes of others.I do disagree with the assertion that it takes a lot of code to convert between the various UTF variants, 3 pages is an overestimate. https://stackoverflow.com/a/148766/5987
Save a file in Notepad. Open in vi. See that it is different. Find data in the database, no clue the weird characters were originally supposed to be. And so on and so forth.
I once wrote a reasonable program and sent it as a bug report to the maintainer of the Perl module DBD::File. He sent it as a bug report to BerkeleyDB. They said they never thought about it but yes, that would be silent data corruption with no way to recover. The program? Maintain an address book in a BTree sorted in the current locale. Enter names. Change locale and insert something else. Voila! Lost data with no way to recover!
More like the ongoing pain.
I had to write the following just this year because SQL Server still defaults to using CP 1252 for text. The culprit? One of those damned stylized quotes that Office loves to insert for you. The code:
def _wrap_str(value: str):
try:
return SqlVarChar(
value.encode("cp1252")
)
except UnicodeEncodeError:
logging.getLogger("bulk copy").exception(f"value causing error: {value}")
raiseIn the Linux/Postgres world, everything is UTF-8. Which is the default for all internet protocols. Do that and the pain is gone.
Of course Windows doesn't do that...
Windows, the OS, is UTF-16 (or UCS-2 - I forget the details between the two), SQL Server has, for historical reasons, defaulted to CP1252, probably for compatibility with Office components.
But, it's not really a Windows problem, per se, because you have to deal with this issue if you deal with data originated from numerous Windows apps, even if on Linux. Yeah, you can insert a byte order mark (BOM) to indicate UTF-8, but most tools expecting UTF-8 actually dont check for the BOM and blow up in interesting ways if present. Ive seen this far too many times. Enough that anytime I see an encoding error from the likes of Python or Ruby, its an instant recognition (I do a lot ETL work from a number of vendors, so I see a lot of different files "types").
https://wiki.postgresql.org/wiki/Abbreviated_keys_glibc_issu...
Since Postgres 10 they use ICU instead of relying on the C library string routines to give more control.
https://www.2ndquadrant.com/en/blog/icu-support-postgresql-1...
I'll quibble just a bit and say that:
a) the C locale should be a UTF-8 locale...
that tolerates invalid sequences (because
the C locale historically is a just-use-8
locale),
b) even with new functions that take a locale
handle, we need functions that use a global
one, however that global one should be set
once and NEVER changed in the life of the
process, and it should be set either before
main() starts, or before main() does anything
that needs a locale, or starts any threads.Such as UTF-8?
Unfortunately it is a bit of a hack that shells out to "file -i", but I'll take it over hours of frustration.
My commits are usually short and sweet - to the point. I document my code very well, however.
One of my strengths in a previous life as a Master Automobile Technician was the ability to document the entire process -- from duplication of a concern, to troubleshooting, to correction, to verification...it's literally how I got paid (which I never understood why so many automotive techs took short cuts while documenting, especially for warranty concerns where you deserve to be paid (by the manufacturer) for everything you did that was necessary to fix the concern the first time).
I could be mistaken (life-long coder, former network engineer / architect for nearly a decade, but I'm currently in my first-ever role as an actual backend developer). I think I was told to keep commits to one line unless absolutely necessary. I'll have to bring this up though. I like the idea of searching through the git logs for specifics, as opposed to having outlook search through the git commits for actual pieces of code changed, or error codes which might not actually be there.
In either event, at least more descriptive, yet still short, messages such as what strictfp suggested "Replace invalid ASCII char. Fixes rake error 'invalid byte sequence in US-ASCII" Although I really like having some reasoning and logic - or how/why in those easily-searchable logs as well.
I think some people remember everything and some people don't (although we're all probably roughly similar logically). I have a hard time remembering what I ate for lunch yesterday - that's why I count on good documentation to function as efficiently as possible in the future. I've worked with people who have an absolute uncanny ability to remember 'stuff'. That's impressive, but I do not have that ability myself.
I think I would phrase something more usefully as: keep it as short as possible, but no shorter.
I find it to be fairly rare that a commit is so self-evident that only the summary line can do.
The advice I've heard: Your first line should be a concise summary of the commit. This is because a lot of UIs only show the first line up front. (GitHub, git log --pretty=oneline, etc.) However, it's okay (and often encouraged) to go into further detail on subsequent lines.
Commit messages should describe why you're doing something ("X asked", or "[reams of supporting evidence why this needed to be made faster but more confusing]"). It provides context to current reviewers, and future archeologists who wonder what you were drinking at the time. Perhaps you had a good reason for doing [insane thing X]! Perhaps you didn't. If you didn't write it down, they might change or leave it, and break something or prevent something from getting a proper fix.
Code comments should be notes to code-readers that are relevant at all times until changed or deleted. "How to use this", "beware changing X", "Z is hot garbage and should be replaced if used for Q". Ideally you'll have asserts or tests or something that actually enforce this, but of course that's not always a realistic option. Comments in code will follow the code around, and don't require chasing code history through N layers of refactoring and indentation-wars, which is what makes commit messages mostly inappropriate for needs like this.
In the article order: the screenshot is from a commit detail page. How often do you land on this page? You need to specifically click through. If you are in a commit list, the only thing that sets title-only commits and commits with description apart is an ellipsis link which practically blends in with the background. It is not very well integrated nor discoverable. Also I don't believe the commit descriptions render as MarkDown (unlike issues) which is also a shame as it feels like less a doc then. But I might be wrong on this. But even outside of GitHub, how many other UI/IDE plugins and other kinds of Git tools restrict commit display to just the title and put the description on the sideline? Most of them. I think this further leads to the currently low value of the commit message being searchable. Since it is exceedingly rare for good commit messages to exist, no one thinks to search them. People default to Google, when their own project's codebase/knowledge base could hold the answer to their query. I don't have much of an opinion on the commit message telling a story / having a human touch. I mean, it doesn't hurt I guess, but until _full_ commit messages become more "mainstream" (for a lack of a better word), they can be as human as they can, but they will live in solitude.
The typical use case would be database migration scripts : IMO they are always a pain to version properly because fundamentally Git and all the other software versioning tools let you describe the "nodes" (in the graph theory sense of the word) of a codebase ("at commit A the code was in this state, at commit B it was in the other state"), but severely lack when it comes to describe the edges between nodes ("in order to go from state A to state B, you need to execute this code")
I think the temporal dimension of software engineering is still poorly understood, and severely undertooled.
Isn't that what a patch file gives ?
A basic example would be - run 'find -name '*.py' -execdir sed -i 's/foo/bar/g' +' on a repo, and commit the result.
For those not familiar with POSIX shell stuff, that will find and replace 'foo' with 'bar' across the repo.
The command is far more understandable at a glance than the patch (commit) and is far more likely to be reviewed properly.
While it should be possible to take a database creation script (state A) and a database migration script (edge A->B) and infer the new resulting database creation script (state B), the reverse is not true.
This is the tables vs events duality described in this great article : https://engineering.linkedin.com/distributed-systems/log-wha...
I tend to go for something like:
This commit was generated.
<shell script here>
It would be super awesome to have a tool that easily verifies that A->B can actually be reproducibly accomplished by performing the actions in the commit message.
It seems you're implying the codebase changed as a result of a script that itself is not source controlled. I can think of style commits falling in this category, like one of the children of this comment mentions, but DB migrations don't seem to be related.
Replace invalid ASCII char. Fixes rake error 'invalid byte sequence in US-ASCII'.
I don't want your entire life story in my commit log.
On the other hand it really gets into my nerves when people don't use the task/issue/whatever manager system appropriately. Recently, I lost a couple of days trying to figure out how to compile a c++ framework because the other guy didn't document his pipeline. In general I'm really disappointed by the majority of my colleagues for the lack of comments inside and outside of our codebase and this is a persistent issue, at all the companies I worked for. Me along with other similarly irritated people, always ask for documentation if it is not given.
Some people do it for job safety. The logic is if you don't document things and the knowledge is only in your head then you are more valuable, they can't get rid of you easily. If you document everything meticulously, then you are easier to replace.
Has anyone actually seen this logic work out well for the person that invokes it? Generally the type of person that uses it is one that you probably don't want on your team.
Company promoted the guy and raised his salary because he had plan to leave the company
This is assuming documenting the pipeline would have been helping! You may have spent a few days instead figuring out why your seemingly identical setup couldn't reproduce the build...
Not that I'm bitter about build systems or anything.
I[1] want enough debug information in the commit log to be able to reproduce the issue without having to go on web hunts to understand the problem. Especially when the change appears to be trivial on the surface, because these are the ones that can turn out to be rabbit holes.
I don't want to have to interrupt you to get this information because you didn't write a good enough commit message, and you probably don't remember anyway. I don't want go look at an external issue tracker that i may not have access to, or may not even exist anymore.
[1] Where "I" is: me, your future self, a future maintainer, a junior dev, an open source contributor.
Related question: are there projects that use git itself as issue tracker?
Comments about the code should be in the code, where the next dev will see it. The more trivial a change, with far- reaching implications, the more important this is.
Doing so has heaps of benefits: future devs understand ramifications, shows that this code has been scrutinized, makes it easier when doing refactoring /yanking, or porting code.
That said, leaving the life story out will always be a good idea.
However, I would have done a simpler commit and linked to an issue where I explained the problem/solution in more detail
Your future maintainer will thank you for not having to dig through repository history.
> immutably
That's what makes this modus operandi so powerful IMO - comments in code may go unmaintained, tests may start failing for other reasons, issue trackers come and go, developers leave the company, documentation rots.
The commit message is (unless you have a bad actor) immutably linked to the original change, and that's exactly why you should be thorough in expressing its reason for being. I can git checkout the point in time (perhaps having bisected) and have the information to allow me to reproduce the issue.
* It ensure that the bug is real. [1]
* It ensures that the bug is fixed. [1]
* It prevents reversions (assuming the test are run automatically).
* The test may prevent reversions in other related code, or discover other hidden bugs.
* It brings you closer to a 100% test coverage.
* You don't have to guess how to reproduce the bug, reading the comment.
* If the bug depends on subtle configurations, they should be set in the test. [2]
From time to time there are bugs that are obvious in the code, but they are too difficult to find a test for them.
[1] Been there, done that.
[2] Once I found a bug that depended on the local timezone.
I don't want to read what the code does (I can read that myself, thanks!), I want to know WHY it does it the way it does it - especially, if there is a more obvious, better way.
Also: People leave companies. Or die. At some point in time, you won't be able to ask the original author.
e.g. the first paragraph doesn't lose any important information trimming it down to:
"After adding a test matching the contents of router_routes.conf, `bundle exec rake` fails with:
ArgumentError:
invalid byte sequence in US-ASCII
"Realistically, it would have been a better commit message if they'd given the shortlog SHA where the test was added that exposed the bug rather than an explanation of what the test does.
"After adding test <testname> (08c3e17), `bundle exec rake` fails with:"
Do other people commit breaking tests and then fixes?
"Commits should always build" is one doctrine I've seen. As you say, it makes bisecting and other error-analysis approaches easy. On the other hand, it risks either having large, opaque commits, or adding overhead to make intermediate commits build - possibly with flawed/meaningless behavior when they do.
Another is "the trunk should always build". In that case, you'd just squash branch commits down to logical groupings that are easy to analyze, whether or not things build. You can bisect on the trunk, but lose all guarantees about state on branches.
Finally, I've seen variations on "no commits that break the product", "no commits that make things worse", or "no committing failing tests without subsequent fixes". In this case, you can't generally commit broken builds, but can specifically add failing tests. The first rule just means "adding failing tests is ok", the second means "converting runtime bugs to failing tests is ok", and the third means "write your test and fix, but split (and ideally tag) the commits". All of these break bisect, but they guarantee the project itself won't become more broken from commit to commit, and they can help with other forms of reasoning about where bugs first occurred.
Every approach there seems viable if you stick to it. If there's no established practice, I suppose the best choice would be based on what sort of work and debugging is most likely to apply.
A good bugfix PR is often two commits then: one with a test to catch the breakage, another to fix it so the tests pass. Reviewers can see the failing-then-passing CI job logs, so if they agree your test catches the bug, they have additional CI-automated validation your fix worked.
Then as long as you squash when completing the merge, you get the best of both worlds.
Something where you can't test locally, like when testing on multiple architectures or when the tests just take too long for a laptop.
It's also a different situation. The original one is "I've made a test that shows a problem." Your example is a surprise "I don't know whether this will pass my cloud-based tests." I would edit my branch if I had a surprise failure, since my initial code clearly wasn't correct.
The powerful thing about this is having everyone put this kind of info in the same place IF they think it might be useful to the next person.
I get you're being terse for demonstrative purposes, but even eschewing verbosity we should still convey all the pertinent information.
My favorite examples of commit messages are the Linux kernel, where you can tell that they're being specifically crafted instead of just used as a work log to be ignored. This means that ten years down the line, people can still see when a change was made and why, who was involved, who signed off on it, etc. Have a look at the commits at https://github.com/torvalds/linux/commits/master
That extreme aside, I'd rather have commit messages that delve into the why-and-how the commit alters the behavior to the better rather than cryptic message as 'Replace invalid ASCII char'. Now we have documented reasoning and thought process that can aid future debugging. They can also be beneficial for new devs hacking on the project, or students learning how to implement and improve systems.
Personally, I enjoy reading these. The Go commits often have commit messages like these, and they are shared on HN often for a reason. They're learning material. They can't go on a wiki because they're tied to particular set of changes in a particular point in history. They also can't be comments on the code because they're tied to particular lines in different files, and code comments can only cover a set of consecutive lines in one file.
One recent example I could find is this[1]. Yeah, it fixes ^Z, but why didn't the old approach work? Why did it work for some time then didn't? How did it change? Why is this commit optimal, if it is? All of this along with scenarios to reproduce the issue.
Give me your life story anytime over cryptic message.
[0] https://github.com/ImageMagick/ImageMagick/commits/master
[1] https://github.com/golang/go/commit/610d522189ed3fcf0d298609...
I believe in the "plane flying across the ocean without WiFi test" or basically anywhere without Internet access. If I am on a plane flying across the ocean without WiFi, do I have the information in the git commit to understand what happened. A git message that consists entirely of a link to a website is useless in that case.
I agree with this, but I think yours is too short.
Scientific papers typically introduce enough information such that a person familiar with the field but not an expert in that particular area can understand generally what's going on.
That's my ideal for a commit message as well: someone generally familiar with the codebase but who hasn't looked at this specific code (or perhaps not in a few months) should be able to understand what's going on; then the job of the reviewer is basically just verification.
My "template" is normally something like: 1) What's the current situation 2) Why that's a problem 3) How this patch fixes it. So in this case, it might look something like this:
---
Convert template to US-ASCII to fix error
$functions use `.with_content(//)` matchers to do X. These matchers require ASCII content. The $foo template contains a non-ASCII space; this results in the following error:
ArgumentError: invalid byte sequence in US-ASCII
Fix this by replacing the non-ASCII space with an ASCII space.
---
No need for a life story, but still searchable, and has enough information for even a casual contributor to do a useful review.
> Replace invalid ASCII char. Fixes rake error 'invalid byte sequence in US-ASCII'. See #123
So people can get the life story if they want it.
There's a balance here and I especially like that this commit message has enough information to make searches really easy should you need to do something like that.
This case is probably longer than necessary, but I've saved a day of debugging on multiple occasions due to someone (also myself) leaving some lines of context, reasons and reasoning after the high-level description.
- git blame (who wrote this?)
- git show (look at the commit surfaced by blame)
Why not? Where else do you want it? Is something forcing you to read the full commit log?
There's no length limit on commit messages and commit messages are mostly out of the way. Most VCSes have a way to only show you the first line. So if you want summaries, that's what the first line is for. If you want the full story, that's what the body is for.
Combined with annotate/blame, commit messages can be very helpful source-level documentation. Nobody has ever complained about too much documentation, and commit messages are the perfect time to document what happened because it's one of the few times where our tools actually force us to write something in order to proceed. As long as we're being forced to write something, write something good and informative.
That said, we reference an ID from our project management software with every commit, so once I find the commit I'm looking for, I can reference it back to external documentation. I still discourage personality there as well because it can get out of hand and clutter the comments, but it's more forgivable than being on the commit itself.
Plus, what if you want to know what happened and you're simply offline? Let's not unnecessarily break the D in DVCS.
You might change your issue tracking solution. You might change your host solution. You might change your review platform. You might also change your VCS solution. Nothing is eternal.
Important information should not just be in PR comments. It should be added into the commit information itself so that it'll be maximally available going forward. A good, fully explanatory commit message is a huge asset, and those commit messages will exist for the entire lifetime of the codebase. Anything else, not so much.
Obvious point is that commit messages can be used besides what was done as a form of documentation and teaching tool (why, how).
There was a whitespace encoding issue AND the developer didn't really understand the issue, since they ended with "One hour of my life I won't get back.". Over my 20 years, I've seen this EXACT scenario multiple times across multiple companies. Some jr engineer gets stuck with some troublesome weird error in a corner-case that ends up being a non-standard whitespace. It's a learning opportunity and he lamented it because it was different and nobody told him "we could stop this from happening again, generate a new issue".
There are salient improvements that the git commit would benefit from both comment changes and additional code:
1. Include a (new) feature ticket that is linked to this issue - to create a process that doesn't allow for this again (eg fix a linter)
2. Include the name of the bug ticket (Convert template to US-ASCII to fix error) in the commit title, that was being addressed.
3. Create a test to specifically enforce the us-ascii encoding or add necessary rules to a linter.
House style in the companies I've worked for is to include a link to a bug report and or code review that provides more context for those who want it. Even without that added context, I'd rather know
Although it's not always practical to follow them in personal/work projects - Linux commits are the results of multiple rounds of reviews, and the commit log is its justification - but in personal/work projects, commits are made in real-time as soon as you debugged/refactored something. But I still use Linux kernel as a guideline for my own commit log, at least for new features or bugfixes.
[0] https://cdn.kernel.org/pub/linux/kernel/v5.x/ChangeLog-5.3.7
In Mathematica, pretty much any object can be a variable name. You can drag a JPEG of Kim Jong-un into Mathematica and integrate an expression with respect to Kim Jong-un. We'd sometimes get a kick out of that.
Near the end of the program, our whole team needed to process the last 3 months of results, but we were all getting consistently incorrect factors off when running our Mathematica notebooks. Five hours later someone discovered that one of the variables contained a stray Unicode whitespace or null character (or maybe a non-Unicode blank Mathematica object, such as a Graphics object with 0 area) that someone must have accidentally spawned somehow before saving and distributed the notebook to the rest of the team. Since Mathematica didn't recognize it as spacing but as part of the variable name, making it a different variable, the result of our integrals were incorrect. E.g. the integral of x^2 is x^3/3, but the integral of xx' is x^2x'/2, so the multiplier would be off by a factor of 3/2.
After discovering and selecting it, we "cut" it into the clipboard, pasted it into another Mathematica notebook, saved it, and it was never opened again.
It took too long for me to track the issue. When I write '#' using alt-3, I then write a space and oftentimes I don't lift alt soon enough and alt-space creates a non-breaking space (on macOS). And some/most Markdown engines don't recognise '#nbsp;text' as a heading.
I suspect something like this happened in the commit linked here.
I’ve since switched my editors to highlight such characters.
I started with these explanatory git commits a few months ago and they are super useful, even if you're just reading your own commits from some time ago.
When you change or switch to a different ticketing system, you will bring these with you.
Issue tracking typically revolves about the who, what, when - not why it happened, or how it was resolved.
This is why I believe that code can never be fully self-documenting. I can't understand why the code exists from reading it. All the floofy contextual stuff is missing, and commits like this help to explain the floofiness.
It’s added complexity, which is something we strive to remove from our code.
1. If I'm looking at some code, I want to see its history without having to switch between git(lab|hub) and jira or whatever system I'm using.
2. The issue tracking system doesn't necessarily have some kind of resolve, a summary of what and why happened. It does have a description and a series of comments, but a summary is usually lacking.
3. I believe my commit history will far outlive any issue tracking system I use. So I'm safer putting information into both.
Putting this in the commit is not easily searchable, not universaly accepted and thus not expected, not practical and certainly can't involve discussion easily. This can be replaced with ticket number as most ticketing systems will actually read commit logs for those in order to associate ticket with code.
Now, there is that problem with decoupling code and story, but this is technical problem, nothing stops Gitlab and friends storring issues and friends in the repository itself.
- Whenever someone asks a question in a pull request, answer it by putting a comment in code. - Include a ticket number (for whatever ticketing system you use) in the commit
Why? I find that commit messages are black boxes. They only come out when doing a git blame, but they don't show up in my IDE. Instead, I'm more likely to run across messages like this when they're comments in code or discussions in our ticketing system.
I think if we had tighter integration among our IDE, git, and the ticketing system, detailed messages commit messages like this would be extremely useful.
If the code is that unclear it needs a comment, refactor it into a named method, where the method name describes exactly what it's doing.
https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...
Basically, ascii is encoded as integers. '32' represents a space. However, ascii is quite limited and if you want non-US-centric characters, you need to use other character sets. For a myriad of reasons, once you go into unicode (the Universal Character Set) there are lots more options for characters. For example, there are multiple whitespace characters.
http://jkorpela.fi/chars/spaces.html
These exist to give different widths or other adjustments to text that is non-ascii. What likely happened in the post (and what did happen to me) is copy-pasting from some document that changed a normal ascii space (that Ruby would expect and know how to deal with) into a unicode character that Ruby interprets as any other character. It would be like having a stray 'g' in the line, but you, as a developer, don't see it. Fun :)
Maybe I'm not as clever, but I'm lucky if I fix an issue like that within a few hours. It can sometimes derail a workday. In fact, fixing in a few hours would be something worth celebrating!
Big problem with detailed comments, things change and comments (like code) can become obsolete/redundant and not reflect the code as the code got updated, but the ocmment did not.
No solid solution really and gets down to preference and also mindfulness of the life of code/comments.
Would be great to have code that you could rightclick and get the documentation, some woudl even prefer being able to write documentation and that gets turned into code, others would love code that could could be autodocumented. Get's down to taste, preferences and more so, experience. See, every programmer over time will eventually encounter a situation on somebody else's code that they are maintaining, fixing or replacing and find that the comments do not reflect the code. You eventually get down to the stage that you almost actively ignore comments based upon such experiences.
So whilst a detailed description in the form of a comment is good, it can and should be elsewhere, either the initial spec and program documentation or in this instance - bug tracking software system and just simple short line with bug reference or indeed just bug reference.
Building "compassion and trust" actually distracts readers from the essence of the commit: what happened and why. I am not discarding the importance of human element in collaborative endeavors but maybe such area should be pursued outside of a version control system.
Mercurial, for example, is functionally identical to git, but some people prefer its interface.
For a highly centralized organization where people only ever work on the organization's intranet, a centralized source-control system like SVN works well enough, and may have some advantages for the organization.
Think fractally. The farther you get from master, the smaller and more atomic each commit should be.
If your merges are taking lots of coordination or failing to auto-merge, you probably have some poor engineering hygeine at play. Every time I've had merge fails, it's due to haste/sloppiness or a dev branch diverging too much from a mainline.
I wish it were easier to gather, annotate and contextualise (perhaps with images) the contents of a commit message.
> One thing Dan did here that I really appreciate was to document the commands he ran at each stage. This can be a great lightweight way to spread knowledge around a team. By reading this commit message, someone can learn quite a few useful tips about the Unix toolset:
> [..]
In the spirit of making everyone smarter: simplicity matters. Using the combination of find -print0 and piping that to xargs -0 is much easier than the mentioned abacadabra of characters.
From the xargs(1) manual:
> The options are as follows:
> -0 Change xargs to expect NUL (``\0'') characters as separators, > instead of spaces and newlines. This is expected to be used in > concert with the -print0 function in find(1).
Code is simple. Humans overthink. I would prefer a commit message such as: "Fix invalid byte sequence in US-ASCII when running bundle exec rspec." than a dev that keep stucked trying to write a cool message and never fix the issue.
That very much varies. In a project where 90% of commits are “fix”, “foo”, “commit”, etc. then yes. Nobody will ever read that (or do pretty much anything else useful with a VCS).
On the other hand, when every commit message is on the level, the yes, people do read them. Actually, first step when investigating any problem or trying to understand some code is to look at the commit log.
See e.g. Linux kernel or some of the Google-related open source projects (chromium, webrtc, etc.) for examples of good, long-form commit messages.
It is so surprising (well not really) to see how, in most cases, developers put so little to close to zero effort in writing proper commit messages and more in general to have a clean commit history. They simply don't care and you keep seeing garbage commits with non-sense to close to empty message and description. Sadly enough this is seen as normal and just accepted.
Every single team I have been working with from small to large organizations I always had to pick up on the "write proper commit history" fight. And even after extensive explanations on why you should do that, people simply don't care and they keep pushing stuff like: "fix", "updated class z" and stuff like that.
Commit history does not seem to be part of the review process.
Sometimes it is just so depressing to see how so unprofessional software engineers are.
Personally, rightly or wrongly, the fact that I can't use Github/Gitlab to contribute to Django and Emacs prevents me from trying to make contributions to those projects. Similarly I find the insistence on using email to send patches, frustrating, when I know PRs (MRs) work so well. However, I guess Emacs and the linux kernel are keeping their good commit messages in their git repo and not losing them to a hosting company.
Maybe there should be tooling for automatically converting a PR intro to a commit message.
I think it's really important to capture the context and indent behind changes. I may be weird, but when I'm fixing an issue, often try to find when it was introduced, which often provides really useful information for the fix. That's much harder to do if the commits aren't cohesive and the messages aren't descriptive.
(Junior developer here, looking to be convinced!)
But ideally interactive rebase before you push your PR and tidy up all those commits into larger topical ones.
Eg.
"DEV-1 - Write tests for widget X calculator" "DEV-1 - Implement widget X calculator" "DEV-1 - Refactor widget X factory service"
I think this is totally OK, just as long as you squash those all down before someone has to merge your PR.
> As long as each commit isn't causing a problem with CI/CD, and my pull request to master is well documented what is the value added of cleaning up commits?
Because it's hard to make sense of all those little commits later, so why keep them around? They're just noise with a very limited future value, and I don't want to have to sift through them in the future. It's basically impossible to clean up those kinds of messes once they get established in master, but it's very easy to contain them at pull request time.
One of my co-workers in my previous job, I miss reading his PR and git message. It's such a joy reading his PR. I still remember reading his PR on introducing Babel to our big, old Rails 4 app before webpacker, Ruby Babel Transpiler came to life. It's like taking a journey with him. You can see his smile, struggle, surprise and all the emotional moments in his commits. He put his findings, why he made this decision, and where he found this solution in the commit msg. I learned a lot just by reading his PR. I think reading a well organized PR, clean git commits and descriptive commit messages (even the code review comments are very useful) is one of the best ways to learn in work, especially for new hires.
Issue: What is the problem we are attempting to fix
Cause: What is the root cause of the issue, since with bug reports this is usually much different then the random musings of the reporter
Fix: How does the commit address the cause.
Each of these should be 1-3 brief lines
Lengthy commit messages are not really required if you have associated tickets in a bug-tracking or project-management system. More often than not, you'll just be duplicating info.
I tend to put a link to the external system with a very brief explanation, allowing someone to quickly assess the what and why with the ability to dig elsewhere for more detail.
Commit logs will have the greatest detail, but they also are the costliest to dig up, often requiring multiple rounds of `blame`. They are therefore most appropriate to include information pertinent at integration-time, namely code review context/justifications.
Merge commits (such as those created during typical PR/MR merges) have similar potential to include explanatory background, but at a coarser granularity, e.g. feature level.
FWIW, I also prefer READMEs to Wikis.
Unless you use Fossil :-P. Or for git/hg/svn/cvs/Folder - Copy(43), one of those ticket trackers that work with files inside the repository itself.
What do you mean? Just put an issue ID in the code and/or commit.
Referring to the issue ID in the commit message is a fine practice in addition to writing good, comprehensive commit messages. Commit messages that consists only of an issue ID are – in my experience – utterly frustrating to deal with. They tell you nothing more than this change is somehow related to this or that bug or feature, but not how or why.
So the solution to a unreliable issue tracking solution is dumping that responsibility on your VCS? Why not fix the concerns you have with your issue tracker?
> writing good, comprehensive commit messages. Commit messages that consists only of an issue ID
Who said anything about only including a tracker id? The issue here is the extra verbosity in the commit message. What will the tracker tickets contain that isn't in your "comprehensive" commit message?
… Or, and hear me out, how about not worrying about that, and just use your VCS to accomplish something it’s imminently well suited for?
Also, how do you propose I solve the issue of the issue tracking service maybe going out of business or that of a more compelling product coming along?
To me, the primary purpose of an issue tracker is to collaborate on and track work in progress, and that’s what I use them for. I don’t find that they are particularly valuable as historical records of the source code.
Porting Jira issues to a different system would probably not preserve those IDs that you entered into your commit message. By all means, refer to your issue tracker in commit messages, but be aware that those references may not be valid in a few years.
> A git repository .. and the commit log and commit hashes stays the same
If issue trackers are so transient and flaky, and VCSs are so solid, then back up your old issue tracker and put it in git. What if your issue tracker stays, but you VCS changes?
In tools like GitHub, if you make a PR with this commit, it will also automatically put the text in the PR description.
I would much prefer this at work over what I usually see with inconsistent commit message styles and not explaining properly what was done, and not following the recommended max length per line.
When a developer is looking at logs for solving some problem, they can easily review the rationale for changes.
I'd much prefer the log explaining everything, rather than having to look to a ticket that may no longer exist.
Why doesn't it? Are closed issues not searchable?
It seems to me you doubt the ticket retention, but instead of fixing that, use commits to store issues instead.
How do you provide comments or updates on an issue "relevant to the commit" without arbitrary commits?
Everywhere I have ever worked has changed ticket systems at one point, and even when they are transferred, the transfer is "lossy".
Heck, just moving from one JIRA version to another can be "lossy".
> How do you provide comments or updates on an issue "relevant to the commit" without arbitrary commits?
In the ticket system. I was not advocating that a ticket system is pointless, because they are very useful.
But a decent commit message about why a change is necessary, especially when it may not be straight forward, can save you plenty of development time further down the line.
If you really need to, put more detailed notes into an "Issues" file for commits/minor releases, and clear it on every major release.
IMO the given example is more verbose that needed. It should give enough information about what and why a fix is done, but no more.
I'd prefer it being on the commit itself.
Code, commit logs, tickets, and project management are all part of the same repo with Fossil.
git log | grep <error message>
git show <commit id>
I don't have to go looking for an issue tracker and figuring out how to search it effectively.In a professional setting, companies usually want this information to live in the issue tracker. Mainly to provide insight to managers/other teams without looking at commit messages.
But it removes the information from the code: you now need to look at the issue tracker to make sense of changes, eg when looking at the history of a file, or with git-blame.
I'd argue that all relevant information that affects the code and architecture of the specific repo should live in commits. They should not only tell you what was changed, but also why; and provide enough context to understand the change in the scope of the repo.
All information that is not directly tied to the code, eg cross-repo/product/etc concerns can go in the issue tracker.
Of course this only works well with a `git commit --fixup` and squash + rebase / squash + merge workflow.
And with monorepos it also becomes a tooling problem.
Not really, the commit message can be informative without being this verbose.
> you now need to look at the issue tracker
Doesn't seem like a bad thing to me. Issue trackers are designed to search through.
I just can’t wait for bigger companies to get onboard. At least in EE/CE it’s tough trying to figure out INTENT sometimes. I see the code, service, headers, docs but you’ve never told me how you intent for me to use this! Maybe your plans were awesome but would change how I was planning to work your thing in. A single page on INTENT would go a long way sometimes.
Raku/Perl6 also has non-ASCII Unicode operators (they all have multicharacter ASCII aliases, but the Unicode characters are usually more readable.)
Things like Péter Rózsa or Kg.m² or ±0.5 PPM or C11 Standard §6.3.1.3/2 all work with my toolchain. Why mangle them into ASCII when there's no need to?
(I guess unless you're using some specific, very performance-conscious system that has to use 7/8-bit characters and is never going to connect to the Internet anyway.)
75% of the development team has at least one non-ASCII character in their name, so it would be pretty rude otherwise.
It's much better to knowingly reject a tool at the start, since it can't handle ordinary characters, than find out a year later with the first e.g. British customer that it can't handle "£".
Edit: already found one. Leet is supposed to end with Compart › unicode “” U+2608 Thunderstorm Unicode Character.
Doesn't show up on my comment.
It's good to check files for unexpected characters, though. Here's some Perl to do it:
perl -e 'binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8");
foreach (split(//, join("", <STDIN>))) { ++$c{$_}; }
foreach (sort(keys %c)) { printf "%8d %s\n", $c{$_}, $_; }'
I tested that on a text file I was working on ... and I discovered that the file contained a BOM (U+FEFF), not at the start of the file, but at a random point in the middle of the file. I've deleted it. Who knows what problems it might have caused for me later?You could have a pre-commit git hook that refers to a whitelist of allowed non-ascii characters, or also allow all alphabetic characters, or something like that.
Over the years, I took the habit to request from my coworkers to write semantic commit messages, like https://www.conventionalcommits.org/
You can use git hook libraries like the python pre-commit or javascript husky to check your git commit messages format.
I wish. You know when this kind of bug happens to you it blows away half a day at least.
“Remove parser-unsupported character. Closes #340295.”
...where ticket 340295 (wherever, not necessarily Github Issues) goes into more detail about the cause, investigation, and resolution process, as a history of the evolution of said process across a conversation.
Using ticket number already forces you to use "the right tool" to view the message.
IMHO I would consider OP example as a bad practice and your example as a better solution.
In other words: if you have a ticket tracker with this information captured in it, it makes some sense to just link to it. But if you have a mailing list with this information captured in it—in only the loosest amalgamation, where there’s no clear “thread” that contains the whole discussion, and the original developer of the patch might not even be a part of that discussion—then it seems like it’d be important for the final committer to write their own summary of the events that led to this commit, such that people can understand what went on if they weren’t following the list. And where do you put that summary? The commit message.
I would argue that maybe this is a core part of git’s design, given that it was developed specifically for the LKML style of “patches first, sent to a list, and then discussed in the context of what they solve”, rather than the GitHub style of “discussion first [on open issues] sparks PRs that attempt to solve [i.e. close] the issue.” Git assumes that you, as an “editor”, are going to be summarizing an otherwise-illegible discussion history for the benefit of the people viewing the commit; and so it provides a multi-line commit message as a place to stow that editorial summary.
By all means put the ticket number in the header line, along with type of patch.
But do yourself a favor and put enough context in too. Doesn't have to be all the detail.
Closes #123456
instead of actual background.It's bad for your codebase.
https://bazaar.launchpad.net/~rbanffy/maas/bug-1443627-incre...
I have never seen any dev searching for error messages in commit messages.
For the rest of the points (makes smarter, builds trust and compassion), if it's so worthy put it on the blog (like this blog post itself) so it can has a potential to reach some reach some audiance.
Having a rich commit message is extremely important for capturing code review discussions and design decisions and glue things together for the set of changes in a single place. The advantages far outweigh any negatives from a short commit message that will not give you the "why" of the solution.
I follow the linux kernel guidelines, which have large descriptions in commits. After all these guys wrote git.
Here's linus's take https://gist.github.com/matthewhudson/1475276
Absent some automated summarising functionality that produces just the right level of detail for you personally, a concise title and a very detailed commit message that you can skim through to find relevant bits is an eminently reasonable compromise.
The problem with that approach is that it doesn't survive as well as you'd like, because fixing a typo in a line would get you "ownership" of the line (since only the last person to change it is blamed). It's even worse in semi-major refactors due to moved/renamed files being treated as new....
Far better to have docs apart.
That's a UI/UX/usability problem with blame, not an inherent one with the practice. Github's blame UI solves this very elegantly (blame history can be traversed easily), as do some others.
> It's even worse in semi-major refactors due to moved/renamed files being treated as new....
This on the other hand is a real problem with Git, but I don't see that it's strictly related to putting context in commit messages. This issue occurs either way.
I've seen many devs search for error messages in Github search. That often turns up results in people's comments in issue threads, but the search also includes commit messages.
But then again, I am not saying "don't write the story". If you think you found something worthy, just write a blog post or even a pastebin/gist would be better in terms of the number of people it reaches.
I like it.
There has to be a balance between this and "WIP"; I'm imagining trying to page through the commit log to see what changed when every 1 line change has a 35 line commit associated with it.
The first line is the title, then there's a description.
These heavy descriptions of commits, are used quite heavily in linux kernel dev
tell me what you did.
then tell me why you did.
leave the saga for the end text so I don't have to read through your musings to get to the meat.
Having a rich commit message is extremely important for capturing code review discussions and design decisions and glue things together for the set of changes in a single place. The advantages far outweigh any negatives from a short commit message that will not give you the "why" of the solution.
The title of the commit was enough for me. I wouldn’t have read the content anyways
For many or most guys out there, reality is way different. For one, it's an actual reality, not VC or government funded Utopia.