Skip to content

Diff local changes within a repository

Git Documentation

Show unified changes to local files within the current repository.

Diff all changes

Calling Diff without options will retrieve all changes within the current repository.

package main

import (
    "log"

    git "github.com/purpleclay/gitz"
)

func main() {
    client, _ := git.NewClient()

    // Changes are made to local files

    _, err := client.Diff()
    if err != nil {
        log.Fatal("failed to diff repository for changes")
    }
}

Diff changes for specific files or folders

To only retrieve changes for specific files or folders, use the WithDiffPaths option.

package main

import (
    "log"

    git "github.com/purpleclay/gitz"
)

func main() {
    client, _ := git.NewClient()

    // Changes are made to local files

    _, err := client.Diff(git.WithDiffPaths("main.go", "internal/cache"))
    if err != nil {
        log.Fatal("failed to diff repository for changes")
    }
}