简体   繁体   中英

Why “gofmt -d” gives “computing diff: exec: ”diff“: executable file not found in %PATH%” error on windows?

I would like to see what mistakes I made in my golang files. In order to figure it out, I issue a command like this:

gofmt -d myfile.go

According to the gofmt --help manual, it is supposed to list the diff of the current and the desired versions of the file. Instead of this, it produces this error message:

computing diff: exec: "diff": executable file not found in %PATH%

How could this be fixed?

The gofmt tool assumes the system has an installed and available diff . Unfortunately, this tool is not part of a standard Windows installation so you need to add it manually.

For most of us, the easiest way to add the path of the diff tool we already have on our computer. This is the one that has been installed as part of git . (If git hasn't been installed yet then do it at first.)

In order to solve this, you should issue a command from the DOS prompt in which you want to execute gofmt :

set PATH=%PATH%;c:\Program Files\Git\usr\bin

(Maybe you need to change the path according to your git installation.)

For a more permanent solution, you should add the path of diff.exe to the PATH environment variable via the Control Panel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM