How to use the command 'delta' (with examples)

How to use the command 'delta' (with examples)

Delta is a viewer for Git and diff output. It allows users to compare files or directories, as well as displaying line numbers and differences side by side. Additionally, it can ignore Git configuration settings and render commit hashes, file names, and line numbers as hyperlinks. The command also provides options to display the current settings and list supported languages and associated file extensions. This article will provide examples for each of these use cases.

Use case 1: Compare files or directories

Code:

delta path/to/old_file_or_directory path/to/new_file_or_directory

Motivation:

  • Use this example when you want to compare the differences between two versions of a file or two directories.
  • This use case is useful for developers who want to analyze changes in their codebase between two commits.

Explanation:

  • path/to/old_file_or_directory: Specifies the path to the old file or directory.
  • path/to/new_file_or_directory: Specifies the path to the new file or directory.

Example output:

┌────────────────────────────────────────────────────────────────────────────────────────────┐
│                                        main.rs                                        │
├────────────────────────────────────────────────────────────────┬───────────────────────┤
│ fn main() {                                                  │ fn main() {             │
│     println!("Hello, world!");                               │     println!("Hello,   │
│ }                                                            │     world!");          │
├────────────────────────────────────────────────────────────────┼───────────────────────┤
│                                                              │                        │
├────────────────────────────────────────────────────────────────┼───────────────────────┤
│ src                                                      | 6,0 │ src                      │
├────────────────────────────────────────────────────────────────┼───────────────────────┤
│ > main.rs                                                 | 5,0 │ > main.rs                 │
├────────────────────────────────────────────────────────────────┼───────────────────────┤
│                                                              │ - fn main() {            │
│                                                              │ -     println!("Hello,  │
│                                                              │ - }                     │
└────────────────────────────────────────────────────────────────┴───────────────────────┘

Use case 2: Compare files or directories, showing line numbers:

Code:

delta --line-numbers path/to/old_file_or_directory path/to/new_file_or_directory

Motivation:

  • Use this example when you want to see the line numbers for the differences between two versions of a file or two directories.
  • This use case is useful for code reviewers who need to provide specific line numbers in their feedback.

Explanation:

  • --line-numbers: Displays line numbers in the output.
  • path/to/old_file_or_directory: Specifies the path to the old file or directory.
  • path/to/new_file_or_directory: Specifies the path to the new file or directory.

Example output:

 1 ┌───────────────────┐
 2 │   fn main() {     │
 3 │       println!(" │
 4 │   }               │
   └───────────────────┘

Use case 3: Compare files or directories, showing differences side by side:

Code:

delta --side-by-side path/to/old_file_or_directory path/to/new_file_or_directory

Motivation:

  • Use this example when you want to compare the differences between two versions of a file or two directories side by side.
  • This use case is particularly useful when you want to see the changes in context.

Explanation:

  • --side-by-side: Displays the differences side by side.
  • path/to/old_file_or_directory: Specifies the path to the old file or directory.
  • path/to/new_file_or_directory: Specifies the path to the new file or directory.

Example output:

│  fn main() {  │  fn main() {
│      println!("Hello, world!");  │ +    println!("Welcome, delta!");
│  }  │  }

Use case 4: Compare files or directories, ignoring Git configuration settings:

Code:

delta --no-gitconfig path/to/old_file_or_directory path/to/new_file_or_directory

Motivation:

  • Use this example when you want to compare the differences between two versions of a file or two directories without considering Git configuration settings.
  • This use case is useful when you want to focus solely on the changes made to a file, regardless of the Git settings.

Explanation:

  • --no-gitconfig: Ignores any Git configuration settings.
  • path/to/old_file_or_directory: Specifies the path to the old file or directory.
  • path/to/new_file_or_directory: Specifies the path to the new file or directory.

Example output (same as Use case 1):

┌────────────────────────────────────────────────────────────────────────────────────────────┐
│                                        main.rs                                        │
├────────────────────────────────────────────────────────────────┬───────────────────────┤
│ fn main() {                                                  │ fn main() {             │
│     println!("Hello, world!");                               │     println!("Hello,   │
│ }                                                            │     world!");          │
├────────────────────────────────────────────────────────────────┼───────────────────────┤
│                                                              │                        │
├────────────────────────────────────────────────────────────────┼───────────────────────┤
│ src                                                      | 6,0 │ src                      │
├────────────────────────────────────────────────

Related Posts

How to use the command 'pacaur' (with examples)

How to use the command 'pacaur' (with examples)

‘pacaur’ is a utility for Arch Linux that allows users to build and install packages from the Arch User Repository (AUR).

Read More
How to use the command flatpak-builder (with examples)

How to use the command flatpak-builder (with examples)

Flatpak-builder is a command-line tool that helps in building and managing Flatpak applications.

Read More
How to use the command az repos (with examples)

How to use the command az repos (with examples)

The az repos command is part of the Azure Command-Line Interface (CLI) and is used to manage Azure DevOps repositories.

Read More