Delta, a new git diff display tool

introduce

Introduction to git diff

Usually we will use related commands on the command line git diffto compare the differences between files. (For the git diff command, please refer to: git-diff command description )

For example: compare the current file with a previous submission of the file, compare the two submission records of a certain file, and compare the differences between any two files on the computer.

However, there is no line number in the git diff comparison, and the differences cannot be displayed side by side. The comparison interface is not very good-looking. At this time, you can use delta.

Introduction

delta is an open source tool for command line comparison. It is based on git, that is, it uses git to compare text to get differences, and then beautifies it. Delta provides many themes and configurations, allowing you to The command line is very convenient to compare codes or texts to improve your work efficiency.

So if you also often use the command line and use the command line to compare, then delta is very suitable for you.

delta's github official website

1. Installation

This article is based on windos to download and install instructions.

1. Download Git

delta is based on Git, if you don't have Git installed, you need to go to the official Git website to download and install Git first.

2. Download delta

According to your operating system, go to the release download page of delta to download the latest version, official website portal: delta download .
Or
download the windos version from Baidu Cloud (link: https://pan.baidu.com/s/1JshHpA8kApTR1MG_i46Cog extraction code: bl5t)

3. Unzip

After downloading and decompressing, put delta.exe in the following directory:

C:\Users\你的用户名\AppData\Local\Microsoft\WindowsApps

4. Modify the configuration file

Open C:\Users\用户名\.gitconfigthe file and add the following configuration in it:

[core]
	pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true		#运行使用 n 和 N 在 diff 部分之间移动
    line-numbers = true  #行号
    side-by-side = true	 #并排对比视图
    syntax-theme = Coldark-Cold #主题

[merge]
    conflictstyle = diff3

[diff]
    colorMoved = default

(If you don’t have a .gitconfig file in this directory, you need to create one yourself)

5. Modify the theme

Above we used the Coldark-Cold theme, which is a theme provided for dark backgrounds.
delta provides a variety of themes for the command line with light and dark backgrounds, you can use delta --list-syntax-themesthe command to view all themes.

亮色背景有以下:
 GitHub
 Monokai Extended Light
 OneHalfLight
 Solarized (light)
 gruvbox-light

暗色背景有以下:
 1337
 Coldark-Cold
 Coldark-Dark
 DarkNeon
 Dracula
 Monokai Extended
 Monokai Extended Bright
 Monokai Extended Origin
 Nord
 OneHalfDark
 Solarized (dark)
 Sublime Snazzy
 TwoDark
 Visual Studio Dark+
 ansi
 base16
 base16-256
 gruvbox-dark
 zenburn

6. Other configurations and instructions

For other delta configurations and custom theme colors, please refer to: delta official configuration instructions

2. Comparison command

1. Common commands of git diff in the project

(1). If multiple files have been modified and none of them have been added to the cache using git add, then you can use the git diff command, which will list all the modified places of these files

git diff

(2). If the Test.java file is not added to the cache using git add, then all the modified places of the file can be listed as follows

git diff Test.java

(3). Compare the difference between a certain submission and the Test.java file in the workspace, XXXX is the commitId

git diff XXXX Test.java

(4). If multiple files have been added to the cache using git add, use the following command to list all the modified places of these files

git diff --cached

(5). If a file has been added to the cache using git add, use the following command to list all the modified places of the file

git diff --cached demo/Test.java

(6). Check the difference between the content of the current workspace and all the files submitted for a certain time

git diff XXXX   #XXXX是 commit Id

(7). Compare all file differences between the two version numbers

git diff XXXX1 XXXX2   #XXXX1和XXXX2是 commit Id

2. Compare two files on the computer

  • Compare revised.txt and original.txt and show their differences (only show differences):
git diff --no-prefix revised.txt original.txt
或者:
detal revised.txt original.txt
  • Comparing revised.txt and original.txt shows the differences and all content of the text:
git diff --no-prefix -U99999 revised.txt original.txt

3. Compare the two folders on the computer

You can use the following command to compare the differences of all files in two folders (dir1 and dir2 are the names of your folders)

detal dir1 dir2

3. Use the effect on the Git command line

1. The effect of the Coldark-Cold theme on the Git command line

Please add a picture description

2. The effect of GitHub bright color theme in the Git command line

If you want to use the bright GitHub theme on the Git command line, you need to change the background color of your command line to white first, right mouse button
==> Options ==> looks ==> Background

Please add a picture description

Please add a picture description

4. Use the effect in the Terminal command line of idea

1. The effect of using the Dracula theme in the terminal command line of idea:

Please add a picture description

2. The effect of using the GitHub theme in the terminal command line of idea:

(GitHub theme is a bright color theme, you need to set the background of the idea to white, in the upper left corner of the idea File --> Setting --> Appearance --> Theme drop-down box under [Appearance & Behavior] select IntelliJ Light)

Please add a picture description

Guess you like

Origin blog.csdn.net/qq_33697094/article/details/131189637