diff

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diff says what changed between two versions of a file, with three lines of context around each change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Lines []Line
	// Added and Removed count the lines.
	Added, Removed int
}

Diff is what changed.

func Compare

func Compare(before, after string) Diff

Compare says what changed from before to after.

type Kind

type Kind int

Kind is what a line of a diff is.

const (
	Same Kind = iota
	Added
	Removed
	Hunk
)

The kinds.

type Line

type Line struct {
	Kind Kind
	Text string
}

Line is a line of a diff.

type Span

type Span struct{ Start, End int }

Span is a part of a line, by byte offsets.

func Inline

func Inline(old, new string) (oldSpans, newSpans []Span)

Inline finds the words that differ between a line deleted and the line added in its place, as the spans of each to mark; none when the lines have too little in common.

It compares words by their longest common subsequence. Should marks read poorly, github.com/sergi/go-diff is the one to compare it with: its DiffCleanupSemantic moves the edges of what changed to where a reader expects them, which this does not do.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL