Live data from Hacker News

Better Git diff output for Ruby, Python, Elixir, Go

tekin.co.uk

41–50 of 53 posts

Re: Better Git diff output for Ruby, Python, Elixir, Go

#41
Wow this is insanity. I thought these would all be the default. I recently introduced .gitattributes into our work codebase, but that was to improve GitHub's ability to hide generated files from PRs:

     # package lockfiles
     poetry.lock -diff linguist-generated=true
     go.sum -diff linguist-generated=true
     yarn.lock -diff linguist-generated=true
     Cargo.lock -diff linguist-generated=true

     # generated protobufs
     *pb2.py -diff linguist-generated=true
     *pb2.pyi -diff linguist-generated=true
     *pb2_grpc.py -diff linguist-generated=true
     *pb2_grpc.pyi -diff linguist-generated=true
     *.pb.go -diff linguist-generated=true

Re: Better Git diff output for Ruby, Python, Elixir, Go

#42
post #8

I use delta as a diff tool: https://github.com/dandavison/delta It also offers contextual information as well as side-by-side diffs. For syntax highlighting, it uses the same as bat (the cat clone).

FWIW, it looked great on paper/Github, so I installed and tried it. The colors just overwhelmed me, so I had to uninstall it.

Thinking "perhaps, it's just the default color scheme", I installed it again and tried the `delta --show-syntax-themes` command to see the themes in action. Didn't like any of them. So uninstalled it again.

I like my current setup, which is:

[core] pager = less -FMRiXx4

Re: Better Git diff output for Ruby, Python, Elixir, Go

#43

I tried to figure out why the extensions aren't configured by default. I found a 2011 patch/proposal to make it the default, which appears to have stranded: https://lore.kernel.org/git/20110825204047.GA9948@sigill.int... With some discussion by the patch's author of possible downsides ( https://lore.kernel.org/git/20110826025913.GC17625@sigill.in... ): > I think it could be a problem in the future if the builtin user…

I rarely see files with incorrect file extensions outside of collisions and user error? I don’t see any downside apart from extensionless files like shell scripts with the executable flag set, shebang, and no file extension which could also be solved. Edit: and if comprehensive correctness was truly desired, file magic could make a better guess, but that would be overkill imo.

What's a '.m' file? Matlab, Objective-C, or Mathematica?

Re: Better Git diff output for Ruby, Python, Elixir, Go

#44
A much bigger set of improvements to the git diff output is also easy to add: https://github.com/so-fancy/diff-so-fancy

This makes your git diff highlight the actual different characters between two lines, makes file names easy to see (and easy to copy, due to no a/ b/), makes renames and blank lines clear and readable.

It is so nice to get all this without a separate GUI diff visualiser when doing anything git-related from the command line.

Re: Better Git diff output for Ruby, Python, Elixir, Go

#45

A bigger problem is tree structures, it is particularly egregious for HTML and JSON where the output tend to be a complete mess of red and green. I think a good solution would be for git to call out to the respective language servers (the VS Language Server Protocol) and render changes based on AST and syntax specific diffs.

Which HTML parsers make an AST available? I can only think of Pandoc.

Re: Better Git diff output for Ruby, Python, Elixir, Go

#47
post #42
post #8

I use delta as a diff tool: https://github.com/dandavison/delta It also offers contextual information as well as side-by-side diffs. For syntax highlighting, it uses the same as bat (the cat clone).

FWIW, it looked great on paper/Github, so I installed and tried it. The colors just overwhelmed me, so I had to uninstall it. Thinking "perhaps, it's just the default color scheme", I installed it again and tried the `delta --show-syntax-themes` command to see the themes in action. Didn't like any of them. So uninstalled it again. I like my current setup, which is: [core] pager = less -FMRiXx4

(Delta author here.) You can disable syntax highlighting, either by customizing the {plus,minus}-*-style options to not use 'syntax' as the foreground color, or by selecting the diff-highlight or diff-so-fancy emulation modes. That would allow you to still have some of the other features if they are attractive to you, such as side-by-side view, line numbers, restructuring and streamlining of the default diff format output, copyable code (no +/- characters), etc.

Re: Better Git diff output for Ruby, Python, Elixir, Go

#49
post #43

Earlier quoted context omitted.

I rarely see files with incorrect file extensions outside of collisions and user error? I don’t see any downside apart from extensionless files like shell scripts with the executable flag set, shebang, and no file extension which could also be solved. Edit: and if comprehensive correctness was truly desired, file magic could make a better guess, but that would be overkill imo.

What's a '.m' file? Matlab, Objective-C, or Mathematica?

It’s an archive hiding in plain sight.
Post reply on HN