Interesting.
In Ye Olden Dayes of (n)curses, there was (and still is) a terminal capacity boolean flag, "xn" or (in terminfo which is more verbose) "xenl", the "terminal eats newline glitch".
Consider your bog-standard 80x24 "glass tty" from the late 1970s / early 1980s. Printing a line of exactly 80 characters caused the cursor to march from column 1, to 2, to 3, ..., to 80, to ... column 81? There is no column 81. So what is this "glass tty" to do?
Some acted like a print head, leaving the cursor stuck in column 80, so that printing *more* characters just made that big black blob of ink on the paper er I mean erased each previous character with the new one printed on top. So then a final "new line" sequence left the cursor on column 1 of the next line, which is where we want it.
Some thought this was annoying and/or stupid so they immediately wrapped to column 1 of the next line, as if the computer had sent a newline sequence. But if the line was in fact exactly 80 characters, this meant the subsequent newline sequence moved to column 1 of the *next* row, leaving a blank line (or scrolling the screen twice or whatever). This is Obviously Bad Behavior, but the "overprint" answer is equally Obviously Bad.
There were two ways of dealing with the problem intelligently: put the cursor to an internal "column 81" that, if there's a newline, sends the cursor to column 1 of the next row; or simply set a flag and eat the next character if it's a newline. (This is a little trickier than it sounds since the newline sequence is actually CR+LF, or LF+CR, depending on certain computer-maker choices, but it works either way.)
The xn / xenl flag describes terminals that behave this way. The screen-oriented programs (ex/vi, now vim and emacs and nano and so on, plus things like "more"/"less"/other pagers, etc) would know to send an extra newline here if the xn/xenl flag is true, and not if not since the cursor was already on column 1 of the next line automatically. (Though actually this depends on another boolean, "am", auto-right-margin. Lacking "am", the cursor simply hammers on the final column, the overprint Bad Behavior Mode.)
Alas, this does not describe what happens if one sends the "clear to end of line" sequence. If the cursor is in the phantom "column 81", perhaps that sequence does nothing. If it's lingering in column 80, perhaps that clears the character under the cursor. All that xn tells you is "send a newline anyway".
As for what to do, well, that could be tricky. Git *could* check for "am" and "xn" / "xenl", but that requires parsing termcap/terminfo, which is kind of a nightmare. It also requires counting cursor column movements, which is something of a mug's game.[1] If you're willing to play that game though, you could just count and, if at the last column as determined by "tty column width" inquiry, omit the ESC [ K entirely: there's nothing to clear. If you have a non-empty prefix string before this "clear to end of line" suffix, the solution is more obvious: print the ESC [ K as a *prefix* rather than a suffix, but that fails with the empty prefix.
One last easy possibility is to print an extra space before the ESC [ K. It's imperfect, as it causes a blank line for these exact-width lines, but avoids data loss.
Chris
[1]: https://www.merriam-webster.com/dictionary/mug%27s%20game