gitrail

package module
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 15 Imported by: ? 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.

README

gitrail

Test Status Coverage Status MIT License PkgGoDev

gitrail tracks file changes over a given time period in a Git repository. It wraps git commands to show which files were added, modified, deleted, or renamed between two points in time, with rename chain detection.

CLI Usage

% gitrail --since="2026-01-01" --until="2026-03-01"
abc123..def456

A	src/new.go
D	src/removed.go
M	src/bar.go	src/old_bar.go
M	src/foo.go
R	src/baz.go	src/old_baz.go
Flags
Flag Default Description
--since required Start time
--until required End time
-C current directory Path to git repository
--branch HEAD Target branch or revision
--json false NDJSON output
--jq none Filter each JSON change with a jq expression
-r false Output raw strings with --jq
-- pathspec... none Git pathspec filters (e.g. '*.go', ':!vendor/')

Time formats are passed directly to git — ISO 8601 (2026-01-01), relative dates ("1 month ago"), etc. are all supported.

Pathspec Filtering

Use -- to pass pathspec patterns and restrict the output to specific paths:

# Only show changes under src/
% gitrail --since="2026-01-01" --until="2026-03-01" -- 'src/'

# Only .go files, excluding vendor/
% gitrail --since="2026-01-01" --until="2026-03-01" -- '*.go' ':!vendor/'
NDJSON Output

With --json, each line is a self-contained JSON object:

% gitrail --since="2026-01-01" --until="2026-03-01" --json
{"to":"def456","status":"Added","path":"src/new.go"}
{"from":"abc123","to":"def456","status":"Modified","path":"src/foo.go"}
{"from":"abc123","to":"def456","status":"Modified","path":"src/bar.go","old_path":"src/old_bar.go"}
{"from":"abc123","to":"def456","status":"Renamed","path":"src/baz.go","old_path":"src/old_baz.go"}
{"from":"abc123","status":"Deleted","path":"src/removed.go"}

The JSON schema is available at schema/output.schema.json.

jq Filtering

Use --jq to filter each change as JSON. --jq works with or without --json and takes precedence when both are set. Use -r to write string results without JSON quoting; non-string results remain JSON encoded, as with jq. A jq evaluation error stops processing and returns an error.

% gitrail --since="2026-01-01" --until="2026-03-01" --jq '.path' -r
src/new.go
src/foo.go
src/bar.go
src/baz.go
src/removed.go
Exit Codes
Code Meaning
0 Success (with or without changes)
1 Error (not a repo, reversed commits, start commit not found, etc.)
2 End commit not found (out of history range)

Agent Skills

gitrail ships an agentskills-compatible skill definition so coding agents can discover and use it directly.

# List embedded skills
% gitrail skills list

# Install skill(s) for the current user
% gitrail skills install

# Install into the current repository
% gitrail skills install --scope=repo

Run gitrail skills --help for all available subcommands.

Library Usage

g := gitrail.New("/path/to/repo")
result, err := g.Trail(ctx, "main",
    time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC),
    time.Date(2026, 3, 1, 0, 0, 0, 0, time.UTC),
)
for _, c := range result.Changes {
    fmt.Printf("%s\t%s\n", c.Status, c.Path)
}

See pkg.go.dev for full API documentation.

Installation

# Install with Homebrew (macOS/Linux)
% brew install Songmu/tap/gitrail

# Install the latest version. (Install it into ./bin/ by default).
% curl -sfL https://raw.githubusercontent.com/Songmu/gitrail/main/install.sh | sh -s

# Specify installation directory ($(go env GOPATH)/bin/) and version.
% curl -sfL https://raw.githubusercontent.com/Songmu/gitrail/main/install.sh | sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z]

# In alpine linux (as it does not come with curl by default)
% wget -O - -q https://raw.githubusercontent.com/Songmu/gitrail/main/install.sh | sh -s [vX.Y.Z]

# go install
% go install github.com/Songmu/gitrail/cmd/gitrail@latest

GitHub Actions

The action installs gitrail and adds it to PATH:

permissions:
  contents: read

steps:
- uses: actions/checkout@v7
- uses: Songmu/gitrail@v0
- run: gitrail

The contents: read permission is required by the checkout step.

Author

Songmu

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, argv []string, outStream, errStream io.Writer) error

Run the gitrail

Types

type ChangeStatus

type ChangeStatus string

ChangeStatus represents the type of file change.

const (
	// Added means the file was added.
	Added ChangeStatus = "Added"
	// Modified means the file was modified. If also renamed, OldPath is set.
	Modified ChangeStatus = "Modified"
	// Renamed means the file was renamed with no content change. OldPath is set.
	Renamed ChangeStatus = "Renamed"
	// Deleted means the file was deleted.
	Deleted ChangeStatus = "Deleted"
)

type FileChange

type FileChange struct {
	Status  ChangeStatus
	Path    string // path at end commit (or start commit for Deleted)
	OldPath string // rename source path (only set when Status is Renamed or Modified with rename)
}

FileChange represents a single file change.

type Gitrail

type Gitrail struct {
	Dir       string    // repo path, defaults to current directory
	ErrStream io.Writer // where git error output is written; defaults to os.Stderr
}

Gitrail tracks file changes over a given time period in a Git repository.

func New

func New(dir string) *Gitrail

New creates a new Gitrail with the given repository directory.

func (*Gitrail) Trail

func (g *Gitrail) Trail(ctx context.Context, branch string, since, until time.Time, pathspecs ...string) (*Result, error)

Trail returns file changes between since and until on the given branch. pathspecs optionally restricts which paths are considered. An empty branch defaults to HEAD.

type Result

type Result struct {
	From    string
	To      string
	Changes []FileChange
}

Result is the output from the Trail method.

Directories

Path Synopsis
cmd
gitrail command

Jump to

Keyboard shortcuts

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