A diff tool especially for Go language.

Overview

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

Issues
  • [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?

    opened by robfig 12
  • 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.

    opened by dmitshur 8
  • 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.

    opened by dmitshur 6
  • 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?

    opened by secretuser1 2
  • 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?

    enhancement 
    opened by metakeule 1
Owner
Yi Deng
Yi Deng
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

Alexey Palazhchenko 50 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

Alex Pliutau 1 Jan 25, 2022
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

crazybie 34 Jul 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

Alvin Leonardo 2 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

KubeSphere SIGs 8 Jul 7, 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

Rakuten Group, Inc. 10 Jul 9, 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

Felix Geisendörfer 14 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

Firda Safridi 3 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

Aswin Karthik 401 Aug 8, 2022
/ˈ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.

null 656 Aug 5, 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

Tufin 113 Aug 4, 2022
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

Vanessasaurus 0 Jan 16, 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

Vanessasaurus 0 Jan 16, 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

UP9 9 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

Guillaume de Sagazan 88 Aug 5, 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

null 41 May 24, 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

Guillaume de Sagazan 89 Aug 1, 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

William Poussier 179 Aug 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

Sergi Mansilla 1.4k Aug 1, 2022
Unified diff parser and printer for Go

go-diff Diff parser and printer for Go. Installing go get -u github.com/sourcegraph/go-diff/diff Usage It doesn't actually compute a diff. It only rea

Sourcegraph 367 Aug 5, 2022
A helm plugin that shows a diff explaining what a helm upgrade would change

Helm Diff Plugin This is a Helm plugin giving your a preview of what a helm upgrade would change.

Fabian Ruff 1.7k Aug 7, 2022
Uses Google's classic diff-match-patch algorithm to compare two files, sending the color highlighted output to *testing.T for use when testing expected versus actual results.

Compare-files uses Google's classic diff-match-patch algorithm to compare two files. It sends the color highlighted output to *testing.T for use when

Read Write Pro 0 Dec 30, 2021
Generate code for any language, with any language.

gocog - generate code for any language, with any language gocog v1.0 build 20130206 Binaries for popular OSes are available on the Downloads page of t

Nate Finch 65 Feb 11, 2021
Floppa programming language inspired by the brainf*ck programming language. Created just for fun and you can convert your brainf*ck code to floppa code.

Floppa Programming Language Created just for fun. But if you want to contribute, why not? Floppa p.l. inspired by the brainf*ck programming language.

null 18 Apr 26, 2022
Please is a cross-language high-performance extensible build system for reproducible multi-language builds.

Please is a cross-language build system with an emphasis on high performance, extensibility and reproducibility. It supports a number of popular languages and can automate nearly any aspect of your build process.

Thought Machine 2.1k Aug 9, 2022
Q Language : A script language for Go

Q Language - A script language for Go 语言特色 与 Go 语言有最好的互操作性。可不进行任何包装即可直接使用 Go 语言的函数、类及其成员变量和方法。 有赖于 Go 语言的互操作性,这门语言直接拥有了一套非常完整且您十分熟悉的标准库,无额外学习成本。 与 Go

null 10 Jul 16, 2022
T# Programming Language. Something like Porth, Forth but written in Go. Stack-oriented programming language.

The T# Programming Language WARNING! THIS LANGUAGE IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! Something like Forth a

T# 92 Jun 29, 2022
A repository for showcasing my knowledge of the Google Go (2009) programming language, and continuing to learn the language.

Learning Google Golang (programming language) Not to be confused with the Go! programming language by Francis McCabe I don't know very much about the

Sean P. Myrick V19.1.7.2 1 Nov 26, 2021