A diff tool especially for Go language.

go-diff GoSearch

A diff tool for Go languange. It shows the semantic differences between two Go source files.

Ignored Difference

  1. Order of import statements
  2. Order of definitions of global type/const/var/func
  3. Whether more than one parameters or global variables are declared in one line. e.g. var a, b int = 1, 2 is equivalent to var a int = 1; var b int = 2. (NOTE parallel assignments are not normalized)
  4. All comments.
  5. Code formats. e.g. some useless new lines.

Other Features

  1. Smart matching algorithm on go ast tree.
  2. If a function is deleted or added as a whole, only one-line message is shown (starting by === or ###)
  3. Easily see which function or type, etc. the difference is in.
  4. Import/const/var/func diffrences are shown in order, independent of the lines' order in the source.
  5. Token based line-line difference presentation.

Installation

$ go get -u github.com/daviddengcn/go-diff
$ go install github.com/daviddengcn/go-diff
$ go-diff <old-file> <new-file>

(Make sure $GO_PATH/bin is in system's $PATH)

Used as git diff

  1. Link scripts/go-diff.gs (you need install gosl) or scripts/go-diff.sh to a folder in PATH

  2. Set Git external diff driver (change go-diff.gs to go-diff.sh accordingly if necessary)

$ git config [--global] diff.external go-diff.gs
$ git diff

License

BSD license

Comments
  • [Feature Request] Support HG - reverse argument order

    [Feature Request] Support HG - reverse argument order

    HG integration would be easy with Extdiff , except that it expects file name arguments in reverse order. e.g. (new file) (original file)

    There doesn't seem to be any easy way to get HG to pass arguments in reverse order, so I was wondering if you were willing to accept a new flag (e.g. --reverse or --hg) that does that?

  • Feature Request: Refactor go-diff into command and package.

    Feature Request: Refactor go-diff into command and package.

    Hi, thanks for making this nice tool.

    I want to use it internally in my Go code, and it would be incredibly helpful if this tool were available both as a Go library that can be imported, with a command-line wrapper binary to preserve the current behavior.

    See goimports as the ideal example of what I mean:

    http://godoc.org/code.google.com/p/go.tools/imports - imports the Go library http://godoc.org/code.google.com/p/go.tools/cmd/goimports - goimports the command (binary), uses imports package

    It was done in PR bradfitz/goimports#30.

  • Add godiff.ExecWriter that works on already-parsed Go files, improve and clean up code.

    Add godiff.ExecWriter that works on already-parsed Go files, improve and clean up code.

    I needed to add a way to get the diff of two already parsed ast.Files, and it was not possible with current API. Exec takes non-parsed Go filenames, and Diff expects FileInfo objects with unexported f, fs fields, and unexported collect method call.

    That's why I added ExecWriter. I used it to implement a little experimental tool that displays semantic diff of Go package at 2 revisions, which you can see here.

    In the process, I've cleaned up and improved various aspects of the code to be nicer and more like Go standard library. The API is now actually readable. Before:

    http://godoc.org/github.com/daviddengcn/go-diff/cmd

    After this PR:

    http://godoc.org/github.com/shurcooL/go-diff/cmd

    So the biggest change is in that one commit 2b8f037e7efd2b1f92f07c51f7afe5f441dc64a5. All other commits are small.

    This change (in a less nice way) was sitting uncommitted on my hard-drive for the last couple of months and it's been really annoying me, so I decided to commit it and make a PR.

  • How can I diff two files from within a Go program?

    How can I diff two files from within a Go program?

    I have two files:

    f1 has the string

    hi how are you
    

    f2 has the string

    hi how are you ?
    im good thanks
    bye
    

    I imported your library in my go program

    import godiff "github.com/daviddengcn/go-diff/cmd"

    I then ran the command after reading the file contents using ioutil.ReadFile function

    godiff.Exec(string(f1), string(f2), godiff.Options{})

    The output does not show the difference properly though..I see something like

    Difference between hi how are you
     and hi how are you ?
    im good thanks
    bye
     ...
    

    What am I missing?

  • Please add a cli option to disable colored output

    Please add a cli option to disable colored output

    Hi, I want to use your tool within the sublime-text2 editor. The result is filled with  sequences...

    Could please add an option, say --no-colors to your tool?

Nut is a tool to manage versioned Go source code packages, called "nuts".

nut Nut is a tool to manage versioned Go source code packages, called "nuts". gonuts.io – central repository (source code) Documents Stable API Mailin

Jul 15, 2021
Github-org-diff - Simple CLI tool to check a diff between 2 branches of all org repos

github-org-diff Simple CLI tool to list org repos that have diff between dev and

Jan 25, 2022
Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications.
Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications.

Linear Allocator for Golang Goal Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications. Pote

Dec 20, 2022
GoFarm is an Application Development Framework for especially Backend Developer with Golang

What is GoFarm GoFarm is an Application Development Framework for especially Backend Developer with Golang. Our goal is to develop easier, standardize

Dec 9, 2021
Help to release a project which especially has multiple git repositories

This project aims to help to release a project which especially has multiple git repositories. Installation Install it to a Kubernetes cluster. You ca

Dec 15, 2022
A minimalistic LDAP server that is meant for test vulnerability to JNDI+LDAP injection attacks in Java, especially CVE-2021-44228.

jndi-ldap-test-server This is a minimalistic LDAP server that is meant for test vulnerability to JNDI+LDAP injection attacks in Java, especially CVE-2

Oct 3, 2022
Measure the overheads of various observability tools, especially profilers.

strong: WIP - NOT READY TO LOOK AT go-observability-bench Terminology Workload: A Go function performing a small task (< 100ms) like parsing a big blo

Apr 23, 2022
maskerito is masking library for golang. Especially for indonesia dictionary.

maskerito maskerito is masking library for golang. Especially for indonesia dictionary. Library maskerito provides a library to do masking struct and

Jul 28, 2022
A fast diff tool for comparing csv files

csvdiff A fast diff tool for comparing csv files. What is csvdiff? Csvdiff is a difftool to compute changes between two csv files. It is not a traditi

Dec 28, 2022
/ˈdʏf/ - diff tool for YAML files, and sometimes JSON
/ˈdʏf/ - diff tool for YAML files, and sometimes JSON

dyff is inspired by the way the old BOSH v1 deployment output reported changes from one version to another by only showing the parts of a YAML file that change.

Dec 29, 2022
A diff tool for OpenAPI Specification 3

OpenAPI Diff This is a diff tool for OpenAPI Spec 3. It can be used in two ways: Generate a diff report in YAML, Text/Markdown or HTML from the cmd-li

Jan 5, 2023
Tool (in Go!) to compare and diff container and host environments. Dinosaur fun!

Compenv compare environments between containers, and host ??️ This is a simple tool to compare environments. This means the environment on your host v

Sep 24, 2022
Tool (in Go!) to compare and diff container and host environments. Dinosaur fun!

Compe compare environments and other things between containers, and host ??️ This is a simple tool to compare environments and other features of conta

Sep 24, 2022
OAS 3.1 Validation and Diff CLI Tool

oas-diff OAS 3.1 Validation and Diff Tool Requisits Go 1.17+ Run Build make build Run ./build/oasdiff --help Examples Validate ./build/oasdiff valid

May 12, 2022
A JSON diff utility

JayDiff A JSON diff utility. Install Downloading the compiled binary Download the latest version of the binary: releases extract the archive and place

Dec 11, 2022
Utility to compare files/directories with output in html. (like unix diff command)

#godiff A File/Directory diff-like comparison tool with HTML output. This program can be use to compare files and directories for differences. When co

Nov 4, 2022
A JSON diff utility

JayDiff A JSON diff utility. Install Downloading the compiled binary Download the latest version of the binary: releases extract the archive and place

Dec 11, 2022
JSON diff library for Go based on RFC6902 (JSON Patch)

jsondiff jsondiff is a Go package for computing the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations, which is particula

Dec 4, 2022
Diff, match and patch text in Go

go-diff go-diff offers algorithms to perform operations required for synchronizing plain text: Compare two texts and return their differences. Perform

Dec 25, 2022