Compare Go code online

A Go program where a function was renamed and the values changed. Paste your own .go files or go.mod to compare them. Tips for Go

Original
0 lines
Drop to load into original
Changed
0 lines
Drop to load into changed
−0+0
Original
Changed

About this Go comparison

Because gofmt keeps Go formatting consistent, a Go diff usually shows only meaningful changes: renamed functions, different values, new branches. That makes comparing two versions of a Go file especially clean.

Use it to review a change before sending it, compare two solutions, or check what a code generator rewrote.

What changed in this sample

  • add(a int, b int) was renamed to calculate(x int, y int).
  • In main, x, y and sum became a, b and total, set to 12 and 18.
  • The threshold moved from 15 to 20, with the printed messages updated to match.

Tips for comparing Go

Compare go.mod and go.sum
Dependency bumps show up as changed version strings; the Characters highlight marks just the digits that moved.
Tabs are part of Go
gofmt indents with tabs. If one version was pasted with spaces, Ignore whitespace treats them as equal.
Generated code
For large generated files, keep Fold unchanged on and use the arrows to step through the changes.
Patch for review
Download .diff file gives a unified diff ready for git apply or a code review tool.

How to compare Go online

  1. Paste the older version into Original and the newer one into Changed, or open a file on each side.
  2. Check that the syntax menu says Go, then pick split or unified view.
  3. Step through the changes with the arrows or Alt ↓, and use Settings for options such as ignoring blank lines.
  4. Save the comparison in your browser, share a link, or download it as a .diff, HTML or PDF.

Go comparison: questions

Can I compare two .go files?

Yes. Open or drop them on the panes and Go highlighting is selected automatically.

Does it run gofmt?

No. It compares the text as it is. Format both files first if they were not formatted the same way.

Is the code sent to a server?

No. Everything stays in your browser unless you create a share link.