8 ms·
Diff So Fancy: make Git diffs look good
- landr0id 11y agoLooks good, but why does it use npm for installation?
- ascorbic 11y agoRight: the package.json is almost as long as the script itself.
- moonlighter 11y agoBecause Paul says so in the original source on line 34... https://github.com/paulirish/dotfiles/blob/master/bin/diff-so-fancy#L34 https://github.com/paulirish/dotfiles/blob/master/bin/diff-s...
- squiguy7 11y agoWhy do I need NPM to install this? I guess I will just have to manually get and link them...
- jdimov10 11y agoBecause there's been this NPM virus infecting our systems over the past few years. It has been disgusing itself as a useful utility.
- Scarblac 11y agoI'm going to assume that is a typo for disgusting.
- richardwhiuk 11y agodisguising I think.
- phinnaeus 11y agoIt looks like the diff-so-fancy script is bash, and the diff-highlight script is perl. Why is it set up in npm? WTF?
- hueving 11y agoAnd you use maven to build it.
- Grue3 11y agoSo that it's web-scale, obviously.
- lucideer 11y agoThere's no easy install methods for small simple scripts that doesn't involve multiple manual steps, have an automated upgrade path, is cross platform and is consistent+familiar to a large subset of developers. Of the options out there for the above, npm - while hassle if you don't have it already installed - is probably the closest balance of maintainer and end-developer convenience.
- phinnaeus 11y agoThanks for the explanation! I went ahead and installed npm to use this, I think it's a pretty nifty little utility and worth it.
- hobarrera 11y agomake install?
- lucideer 11y agoNothing wrong with make, but to be fair, it doesn't really meet any of the criteria I mentioned - no built-in remote repos / app directory so it's just the final step of multiple install steps - no built-in automated upgrade path - unless you're fiddling with Cygwin or MSys2, it's not really as cross-platform - likely to be less convenient for the maintainer than the package.json standard
- pierrebeaucamp 11y agoI know he gave credit in the README, but why does this ~30 line shell script need its own repo? Seems more like a cheap grab for Github Stars rather than to provide actual value. Edit: Even the screenshot is from Paul...
- paulirish 11y agoA bit ago, I had indicated this script should be more accessible than copying two separate files out of my dotfiles repo: https://github.com/paulirish/dotfiles/blob/master/bin/diff-so-fancy#L34 https://github.com/paulirish/dotfiles/blob/master/bin/diff-s... Steve took the initiative to put this in it's own repo. Seems okay; I was being rather slow to ship it for real.
- pierrebeaucamp 11y agoAll good then ;)
- ceejayoz 11y agoSheesh. The repo allows the stuff like installing it via `npm install -g diff-so-fancy`. It's not like a public repo costs anything, and Github stars don't get you anything either.
- stevemao 11y agoI think it makes it easier to add contributors. Git doesn't allow a user partially access a repo so Paul would add a few people only contributing on one script. I added some really talented contributors :) The repo under my name doesn't mean it belongs to me. In fact it belongs to the public. Everyone can contribute to it so everyone is the "owner". That's how I see open source projects. I don't mind giving it back to Paul. I did it only because I needed it. I believe a lot of people would want it more accessible too.
- jrochkind1 11y agoWhy doesn't any code you are using need it's own repo, to track history, what does it matter how short it is?
- chaitanya 11y agoMight be better to link to the source directly: https://github.com/paulirish/dotfiles/blob/master/bin/diff-so-fancy https://github.com/paulirish/dotfiles/blob/master/bin/diff-s...
- izolate 11y agoRemove contextual +/- in favour of colour highlights? As a person with red-green colourblindness all I can say is: Lol. Nope.
- scrollaway 11y agoYou know you can customize the diff colors, yes? From the git book itself: `git config --global color.diff.meta "blue black bold"`
- brokentone 11y agoThat's a helpful perspective, but hopefully you already have workarounds on the color issue. This is simply making diff pieces easier to copy / pasta -- which I for one have needed to do. Change my mind on a refactor midstream, need to restore part of the file, etc.
- deleted 11y ago[deleted]
- tomjakubowski 11y agoYou might investigate the tools your editor of choice provides for working with diffs. You might be surprised at how easy it can be! (In Emacs, if you're using git, magit is an amazing package. You can select a commit from the logs, dive into the diff for a file caused by that commit, highlight a region of the diff and revert the change in your working copy. It's wonderful.)
- joeheyming 11y agoCame here for someone to shout-out magit. It's amazing
- jimrandomh 11y agoA personal pet peeve of mine when reading diffs, is when a file has some functions and you insert one and instead of looking like this: int someOldFunction() { // Function body } + +int newFunction() +{ + // New function body +} It looks like this: int someOldFunction() { // Function body +} + +int newFunction() +{ + // New function body } It's a small thing, but given that these diffs are equivalent, the one that balances the curly braces within added blocks should be favored. But diff utilities seem to get this pretty consistently wrong.
- stormbrew 11y agogit diff --patience might give you better results? I've seen this pattern too, but I can't find a reproduction of normal git diff giving it to me at the moment.
- stock_toaster 11y agoI use this in my ~/.gitconfig [diff] algorithm = patience
- paulirish 11y agoI've experimented with patience diff, but not seen it deliver reliably superior results than myers (the current default).
- aidenn0 11y agoI saw it deliver superior results enough that I spent a while figuring out how to get vimdiff to use patience.
- fredmorcos 11y agoAnd? What do I need to do to get that? :)
- 11y ago
- finnn 11y agoSo, the whole npm thing seems weird to me, then it occurred to me that it could be for malicious purposes. Would it be possible to upload a separate package.json to npm that had eg a post-install script? I don't know much about how npm works from the package publication side of things, but I assumed it was similar to pypi where the code in the git repo doesn't have to be at all related to the code in the package
- merb 11y agothis doesn't look useful. the left one is just fine. for everything else you wouldn't need a cli diff tool...
- nqzero 11y agowhen one or 2 words change in a long or dense line, it's nice to have the specific changes highlighted imagine a for loop in which a variable (used on every line) was renamed, and buried in the loop an assignment changed slightly (eg, + became -). with a standard diff, it's really hard (for me) to pick up the minor change. with word by word diffs, it's pretty easy (i use netbeans diff, not this tool, but they appear similar)
- deleted 11y ago[deleted]
- timtadh 11y agogit diff --word-diff=color provides a really nice word diff with coloring similar to this project. Just setup an alias in your global gitconfig: [alias] cdiff = diff --word-diff=color
- mrinterweb 11y agoVim's fugitive plugin also gives a similar split diff view. The command is "Gdiff".
- ilikepi 11y agoEven without the plugin, you can spawn a diff in vim via git's difftool settings. Here's a basic version that can be used in one's .gitconfig: [diff] tool = customvim [difftool "customvim"] cmd = vim -R -f -d \"$LOCAL\" \"$REMOTE\"
- paulirish 11y ago[I'm the author of diff-so-fancy, Steve helped with shipping it as a standalone script] NPM?!? :) A lot of people below are asking why a bash script (that depends on a perl script) is being recommended to install via NPM? The short reason is that NPM is the most straightforward way to get a script installed as a global binary in a cross-platform manner. This approach has worked quite well with `git-open`[0]. Asking all users to deal with the PATH is not my ideal. In addition, I wanted a reasonable upgrade path, in case there are neccessary bugfixes. It's not a great experience if users identify bugs but the fix means they manually find it/download/PATH-ify each time. :/ That said, I'll add some Manual Install instructions to the readme so it's clear how to do this on your own. :) ( Edit: Here they are… https://github.com/stevemao/diff-so-fancy/blob/master/readme.md#manual-install https://github.com/stevemao/diff-so-fancy/blob/master/readme... ) [0] https://github.com/paulirish/git-open https://github.com/paulirish/git-open
- semi-extrinsic 11y agoWouldn't it be easier for the end user if you used pip/PyPi? Essentially all Linux distros include Python, but there are very few that ship with Node.js installed by default.
- LyndsySimon 11y agoI can only speak for myself, but my systems all prohibit installation of packages into the system Python namespace by default.
- tomjakubowski 11y agoYeah, I try to avoid "sudo pip install" for CLI utilities if I can (and discourage its use to others). I put ~/.local/bin on my PATH (nonstandard XDG -like convention) and use "pip install --user" instead. I've seen too many Python environments hosed by folks who aren't Python experts to keep suggesting that "sudo pip install <CLI tool>" is a thing most users should be doing.
- 11y ago
- _ZeD_ 11y agowhat are the advantages over colordiff[0]? (or a graphic differ like kdiff3[1]) [0] http://www.colordiff.org/ http://www.colordiff.org/ [1] http://kdiff3.sourceforge.net/ http://kdiff3.sourceforge.net/
- jfountain2015 11y agoNice improvement to diff but I think I'll still use `git difftool` with Diffmerge https://sourcegear.com/diffmerge/ https://sourcegear.com/diffmerge/
- FiloSottile 11y agoIf you don't want your diff so fancy (pun intended, and I'm sorry) but you still want the inline highlights, the script comes with git (https://github.com/git/git/tree/master/contrib/diff-highlight https://github.com/git/git/tree/master/contrib/diff-highligh...): ln -sf "$(brew --prefix)/share/git-core/contrib/diff-highlight/diff-highlight" ~/bin/diff-highlight and add to .gitconfig [pager] log = diff-highlight | less show = diff-highlight | less diff = diff-highlight | less
- makecheck 11y agoI handle this in a way that is more agnostic to the type of revision control, and fully flexible in coloring (using the most powerful scheme available). For example, I shouldn't have to put up with basic colors if the terminal can do better. Here is how it works; starting with: #!/bin/bash if [ -r ".svn" ] ; then exec svn diff ${1+"$@"} | my_colorize_diff else git diff ${1+"$@"} | my_colorize_diff fi ...where the "my_colorize_diff" script at the end of the pipe is as follows: #!/usr/bin/env perl # by Kevin Grant (kmg@mac.com) my $term_program = (exists $ENV{'TERM_PROGRAM'} && defined $ENV{'TERM_PROGRAM'}) ? $ENV{'TERM_PROGRAM'} : ''; my $term = (exists $ENV{'TERM'} && defined $ENV{'TERM'}) ? $ENV{'TERM'} : 'vt100'; my $is_xterm = ($term =~ /xterm/); my $is_24bit = ($term_program =~ /MacTerm/); print "\033#3BEGIN DIFF\n"; print "\033#4BEGIN DIFF\n\033#5"; while (<>) { if (/^\+/ && !/^\+\+/) { if ($is_24bit) { print "\033[48:2:150:200:150m", "\033[2K", "\033[38:2::88:m", "\033[1m"; } elsif ($is_xterm) { print "\033[48;5;149m", "\033[2K", "\033[38;5;235m", "\033[1m"; } else { print "\033[42m", "\033[2K", "\033[30m", "\033[1m"; } } elsif (/^\-/ && !/^\-\-/) { if ($is_24bit) { print "\033[48:2:244:150:150m", "\033[2K", "\033[38:2:144:0::m"; } elsif ($is_xterm) { print "\033[48;5;52m", "\033[2K", "\033[38;5;124m"; } else { print "\033[41m", "\033[2K", "\033[37m"; } } else { print "\033[3m"; } chomp; print; print "\033[0m\n"; } print "\033#3END DIFF\n"; print "\033#4END DIFF\n\033#5";
- thristian 11y agoFor what it's worth, there's a lot of 24-bit-capable terminals that aren't MacTerm. Even xterm supports the 24-bit-color sequences, although it picks the closest entry in its 256-colour palette rather than using the 24-bit colour directly. Also, you seem to be assuming "xterm" supports 256 colours and everything else doesn't. The best way to figure out how many colours the terminal supports is $(tput colours). tput also looks up other useful sequences; you can "tput bold" to turn on bold mode, "tput setaf 12" to set the foreground to colour 12 (bright yellow), "tput sgr0" to zero all active formatting, etc.
- makecheck 11y agoGood point. Although, unless there are shells that have "tput" built-in, that means more subprocesses to obtain basic information (which would slow down the result a bit). In my case, the environment is sufficient to figure out what to do.
- AdmiralAsshat 11y agoSo what does this offer over simply using vimdiff?
- oabm 11y agoWhat happened to this line from the second file in the screenshot? - var optionsGlassPane = new WebInspector.GlassPane(document); An important part of viewing diffs for me is seeing what the old code was.
- nqzero 11y agothe netbeans.team.diff tool is similar (showing the specific words that changed), allows interactive editing, and does a good job even with large insertions and deletions
- Animats 11y agoHurts. Hurts bad. Tiny type in many primary colors on a black background. 1985 called, it wants its screen layout back.
- mschuster91 11y agowhat I'd like to see is that a/b in front of the filenames disappear. Getting rid of that would FINALLY allow me to double-click on the filename (which is configured to select the part between the spaces and copy it to the clipboard) and paste it instantly for the next command... or to be able to do git diff > foo.patch and on another system do patch < foo.patch without having to remember the correct -p value.
- datashaman 11y agogit diff --no-prefix
- tremguy 11y ago> No pesky + or - at line-stars, making for easier copy-paste. I wonder if easing copypasting is a good or bad thing..
- module17 11y agoIt looks so good and real, I kept hitting `q` whilst looking at the image.
- deleted 11y ago[deleted]
- GreaterFool 11y agoIs there any language aware diff tool? I think I saw some commercial product for Java but other than that I haven't seen any attempts to do that.
- nikolay 11y agoI find icdiff [0] (Improved Colored Diff) better. [0]: https://github.com/jeffkaufman https://github.com/jeffkaufman
- samuell 11y agoWhen writing manuscripts in git, my favourite "trick" is git diff --word-diff (of course aliased to git wdiff).
- felipesabino 11y agoI have an alias for the diff params bellow, which has basically the same visual result, without the need to install anything. $ git diff --color --color-words --abbrev
- stevemao 11y agoWe've grown and it's out of control. diff-so-fancy moved to an org!!! https://github.com/so-fancy/diff-so-fancy https://github.com/so-fancy/diff-so-fancy
- hobarrera 11y agoI didn't quite like this, put it does reference diff-hightlight, which is part of git-contrib (so it may already be installed on your system, but just not in your $PATH!): https://github.com/git/git/tree/master/contrib/diff-highlight https://github.com/git/git/tree/master/contrib/diff-highligh... For example, here's a diff where it improved readability enormously: https://i.imgur.com/8iQNaeu.png https://i.imgur.com/8iQNaeu.png
- hobarrera 11y agoYes, the code in that sample is horrible triplicate. Please ignore that.