Home >Backend Development >Golang >How Can I Pin Go Module Dependencies to Specific Git Commits?
Customizing Go Module Dependencies to Point to Specific Commits
Go modules provide a mechanism for managing package dependencies in Go projects. By default, modules use the latest released version of a dependency. However, there may be instances where you require functionality not included in a published release.
Manual Dependency Specification
One approach to specifying a custom dependency is to modify the go.mod file manually. This can be achieved by appending the desired commit hash to the module version, as demonstrated below:
module /my/module require ( ... github.com/someone/some_module v0.0.0-20181121201909-af044c0995fe ... )
Go Get Command
A simpler method is to use the go get command with the desired commit hash:
go get github.com/someone/some_module@af044c0995fe
This command will automatically update the go.mod and go.sum files to reflect the custom dependency.
Advantages of Using Go Get
Compared to manual modification of the go.mod file, using go get offers several advantages:
For further information, refer to the Go Wiki page on modules: https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies
The above is the detailed content of How Can I Pin Go Module Dependencies to Specific Git Commits?. For more information, please follow other related articles on the PHP Chinese website!