1. In VS Code, pressing Ctrl + S reverts the file to its previous state instead of saving it as expected.
Before modification:
Go
import (
"fmt"
)
After modification:
Go
import (
"fmt"
"math"
)
After Ctrl + S:
Go
import (
"fmt"
)
2. First, perform a key check: open the Visual Studio Code settings by pressing Ctrl + , and search for “format on save” to see whether “Editor: Format On Save” is enabled. I found that it was enabled (modified elsewhere). See Figure 1.

3. Ctrl+S is not “undoing”; rather, Go’s automatic formatting tool reverts the code to a valid state. The reason is the code in the file: after changing math.pi to math.Pi, Ctrl+S saves the file normally.
Go
package main
import (
"fmt"
)
func main() {
fmt.Println(math.pi)
}
Go
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(math.Pi)
}
