Home > Backend Development > Golang > How Can I Point a Go Module Dependency to a Specific Git Commit?

How Can I Point a Go Module Dependency to a Specific Git Commit?

Mary-Kate Olsen
Release: 2024-12-31 22:59:16
Original
502 people have browsed it

How Can I Point a Go Module Dependency to a Specific Git Commit?

Pointing Go Module Dependency in go.mod to a Latest Commit in a Repo

Go modules provide a structured approach to managing dependencies in Go projects. By default, go.mod files contain references to specific releases of dependencies. However, sometimes it's necessary to point to a specific commit in a repository instead.

In such cases, simply use the go get command followed by the commit hash:

$ go get github.com/someone/some_module@af044c0995fe
Copy after login

This command will correctly update the go.mod and go.sum files, linking the dependency to the specified commit.

Notably, this method is more convenient and reliable than manually editing the go.mod file. It ensures that the dependency version is treated as a non-release version, and it automatically updates the go.sum file with the correct checksums.

For further information and guidance on upgrading and downgrading dependencies, refer to the Go wiki: https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies

The above is the detailed content of How Can I Point a Go Module Dependency to a Specific Git Commit?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template