Beware of long lines in git

14.08.2013 15:45

These days I use git almost exclusively for version management. Not just for code, but also sometimes for plain text or LaTeX documents. One thing that soon becomes apparent when using git for prose is that default command line tools are very bad at handling long lines. There are some workarounds that improve the situation somewhat, but you have to remember to apply them on a per-repository basis and don't solve all problems.

However, recently I noticed that this deficiency can also become a problem when handling code contributions and pull requests on GitHub.

Take for instance this example where you are merging in some changes from someone else's branch. git diff doesn't show any indication that something may be hidden beyond the right edge of the terminal:

git diff --cached output for modified hello-world.c

A pull request on GitHub fares marginally better. Here you at least get a scroll bar at the bottom that hints at the fact that something may be amiss. However, if this branch would contain some more changes, the scroll bar could be several screen heights below the line that is causing it. Unless you have a mouse that can do horizontal scrolls it becomes practically impossible to review code like that (the view port is also conveniently set to fixed width, so resizing the browser window doesn't help).

To be honest, until yesterday I didn't even notice that you get a scroll bar.

GitHub pull request example.

Only opening the modified file in an editor that will automatically break long lines (and not all of them do that!) will unambiguously reveal the complete content of the pull request.

Modified hello-world.c opened in vi.

So I guess the conclusion would be to not accept pull requests from untrusted sources based solely on git diff output and be mindful of scroll bars on GitHub.

Posted by Tomaž | Categories: Code


Thus it is probably useful to use things like or other linting solutions that check for line lengths before accepting a pull request. I did some rough research but not enough to be confident of how to add a commit hook into github that would make sure the linter was run and the committer is at least aware of the violations.

Piotr, at work I've rolled my own minimal continuous integration server for embedded development we're doing on GitHub. I'm planning to also add some code style checks in the future.

It's probably a good example of how you can attach commit statuses to GitHub pull requests with minimal code. You can find it here:

Posted by Tomaž

Git is a perfect example of a GOOD IDEA
I never seen a so awful confusing non intuitive and non consistent set of commands
AND you need to know A LOT of them in order to do the minimum

I hope someone will take the same high level idea but make a decent implementation

Posted by NICOLAS

Add a new comment

(No HTML tags allowed. Separate paragraphs with a blank line.)