๐Ÿ“ฆ josephfrazier / prettier-diff

`git diff` wrapper for semantic JavaScript/JSON diffs

โ˜… 36 stars โ‘‚ 2 forks ๐Ÿ‘ 36 watching
๐Ÿ“ฅ Clone https://github.com/josephfrazier/prettier-diff.git
HTTPS git clone https://github.com/josephfrazier/prettier-diff.git
SSH git clone git@github.com:josephfrazier/prettier-diff.git
CLI gh repo clone josephfrazier/prettier-diff
dependabot[bot] dependabot[bot] Bump js-yaml from 3.14.1 to 3.14.2 (#12) 9d7da79 1 months ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ bin
๐Ÿ“ test
๐Ÿ“„ .eslintrc.js
๐Ÿ“„ .gitignore
๐Ÿ“„ .vimrc
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ screenshot.png
๐Ÿ“„ TODO.md
๐Ÿ“„ yarn.lock
๐Ÿ“„ README.md

prettier-diff

prettier-diff is a git diff wrapper that preprocesses JavaScript and JSON files to reduce the number of formatting changes that appear in the diff. This allows you to focus on the semantic changes, which is useful when viewing diffs that also have formatting changes.

JavaScript is preprocessed with [prettier], and JSON is preprocessed with [json-stable-stringify] and [json-align].

Installation

You can use [yarn] or [npm] to install prettier-diff:

yarn global add prettier-diff
# or
npm install --global prettier-diff

Usage

One-off usage

In any git repository, just use prettier-diff instead of git diff:

# instead of
git diff head^^
# do this
prettier-diff head^^

Behind the scenes, prettier-diff temporarily modifies the .git/config and .git/info/attributes files to set up the preprocessing by defining a [textconv] for all files.

git diff integration

To always use prettier-diff as part of git diff in a given repository, you can run the following:

git config diff.prettier.textconv textconv-prettier

echo '*.js diff=prettier' >> .gitattributes
echo '*.json diff=prettier' >> .gitattributes

Now, git diff will automatically run prettier-diff on your JS/JSON files, and it plays well with the other git diff options like --ignore-all-space, as well as [diff-so-fancy]. See here for more information: [textconv]

Examples

For example, this repository contains a large commit that rewrote most of its code with [prettier-standard], and also renames a variable. You can see the commit on GitHub here: [8cc0119]

With prettier-diff, only the renaming is shown:

prettier-diff 8cc0119^ 8cc0119 --color | diff-so-fancy

screenshot of <code>prettier-diff 8cc0119^ 8cc0119 --color | diff-so-fancy</code>