Better Git diff output for Ruby, Python, Elixir, Go
tekin.co.uk
tekin.co.uk
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 userdiff drivers started growing more invasive options, like automatically claiming to be non-binary (i.e., setting diff.cpp.binary = false by default). In other words, I think we have two options:
> 1. Builtin drivers like "cpp" can stay minimal, only setting funcname and color-words headers that aren't going to produce terrible results if we are wrong about detecting by extension.
> 2. We force the user to identify file types manually, so we can't be wrong. The "cpp" diff driver means "you are a text C file", and if a user mis-marks a binary file with that diff driver, they are the one who is wrong.
> So if it's an either/or situation, we should decide not only that extension auto-detection is a good feature, but that it trumps adding more advanced features to the builtin drivers in the future.
> Or we could decide that the extensions really are good enough, and if you really do have binary files named "foo.c", it's your problem to override the defaults with "*.c -diff".
There might be more recent discussion that I didn't find.
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.
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).
It's properly fast, the diff/stage/commit/etc UX is excellent. I particularly enjoy how straightforward it makes it to hand-pick lines from multiple files really quickly. The interface abstracts over enough of the Git ux/api to make it get out of your way, but in a way that doesn't make what it's doing a mystery or too out of your control - hovering over a button will often yield the equivalent git cli commands for example.
Personal preference here, but it's also not an electron app, so it's very resource light.
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
I've been using kdiff3 even though it hasn't been updated in a very long time because it has one killer feature: manual diff alignment. I can select a token in both (or all three) files and then force the diff to align at that point. It makes merges a whole lot easier. Sometimes, a single realign is all that's needed for a file merge to sort itself out. Even when that's not the case, it's easier to reason about the changes.
Did I miss something? That is, is that feature available in other diff/merge tools and I just haven't seen it?
Sure
In theory there's newer builds of kdiff3 but I've not had any luck running the Windows versions & I don't think there's been significant improvements to the manual alignment code which still require a lot of battling to get the right outcome.
I was expecting something like MergeResolver which diffs Javascript ASTs:
I don't think it has syntax-aware alignment, though.
git config --global core.attributesfile ~/.gitattributes
Git looks for your personal attributes file by default in ~/.config/git/attributes (well, $XDG_CONFIG_HOME/git/attributes to be precise), so if you put it there you don't have to set the config option.Instead of a regex per file type perhaps a better diff tool could actually diff the parsed code (if possible) and produce a more sensible diff and context?
Though, being able to refactor code, and assert that it is logically and functionally equivalent as the previous checkin would be super useful, even if there’s some gaps (sting value or comparison changes could not be asserted, for example)
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.
# 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=trueThis should speed up my adds, and cut down on accidental stagings.
I’m curious if others see some value in it, either before or with changes from this post?
Edit: got it. Thanks!
@@ -24,7 +24,7 @@ class TicketPdf
Configured: @@ -24,7 +24,7 @@ def tickets_as_html assigns: {
tickets: tickets,
++ event_name: event_name
}