37

How to customize git diff to spot changes faster

 4 years ago
source link: https://gitbetter.substack.com/p/how-to-customize-git-diff-to-spot
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to customize git diff to spot changes faster

diff-so-fancy is a tool that helps you to customize your diff view

https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F286420a7-290d-42c6-997a-4d4ae2cb3dfc_940x788.png

git diff is one of the most useful features in git. Customizing diff will make your life easier.

Diff-so-fancy is the git tool that helps you to make good looking diffs. This tool helps you to spot the differences without any human error.

You can view the package in this repo

Let’s see that in-depth

Installation

Diff-so-fancy is available in brew, npm and also as a package for Debian Linux

brew install diff-so-fancy

npm i diff-so-fancy --global

Usage

I will explain a few ways of using diff-so-fancy. You can choose your way of doing it.

Be default, diff-so-fancy will never change any default diff options. You should explicitly mention it.

git diff | diff-so-fancy

The above command will use diff-so-fancy to display the difference.

https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7f1221f1-5acb-4d37-b2ae-c01d32359727_809x458.png

If you want to make diff-so-fancy as default diff viewer, you can use

git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"

Now you can just use git diff to use diff-so-fancy.

Now for some reason, you may wish to use the default git diff to view the change even after setting diff-so-fancy.

In that case, you can use

git --no-pager diff

The above command will bypass diff-so-fancy. So the default diff view will be used.

Remove diff-so-fancy from the default option

To remove diff-so-fancy from the default git diff, you can set the pager as

git config --global core.pager 'less'

Git uses a pager to display the content. Pager is used in commands like git-diff, git-log. By default, a pager called less is used by Git.

So in the above command, I have set the default pager to Git.

diff-so-fancy comes with few options. You can see that in the repo.

That’s it for today :)

See you next week :) :)

And remember if you want me to cover some specific topics, you can reply to this email. I’m running this newsletter for you and I’m always open for ideas :) :)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK