In VS Code Ctrl + S, the file is restored to the previous step
1. In VS Code Ctrl + S, the file is restored to the previous step, not the expected save file
Before modification:
import (
"fmt"
)
After modification:
import (
"fmt"
"math"
)
After Ctrl + S :
import (
"fmt"
)
2. Do a key check first, open the Visual Studio Code settings: press: Ctrl + , search: format on save to see if it is enabled: editor: format on save, and find (Modified elsewhere). as shown in Figure 1

3. It is not that Ctrl+S is ‘undo’, but Go’s automatic formatting tool changes the code to the legal state. The reason is that the code of the file is as follows, math.pi is modified to math.pi, and ctrl+s can be saved normally.
package main
import (
"fmt"
)
func main() {
fmt.Println(math.pi)
}
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Pi)
}