goのプロジェクトでライブラリのバージョンをgo.modで固定したい場合もあると思います。
https://go.dev/ref/mod#go-mod-file-replace
その際に便利なのが上記の replaceディレクティブです。
公式ではこのように記載されています。
A replace directive replaces the contents of a specific version of a module, or all versions of a module, with contents found elsewhere. The replacement may be specified with either another module path and version, or a platform-specific file path.
replace ディレクティブは、特定のバージョンのモジュール、またはすべてのバージョンのモジュールの内容を、別の場所にある内容に置き換えるものです。置き換えの際には、別のモジュールのパスとバージョン、あるいはプラットフォーム固有のファイルパスを指定することができます。
require golang.org/x/net v1.2.3
replace (
// こちらはv1.2.3のx/netのみ"example.com/fork/net v1.4.5"に置き換える
golang.org/x/net v1.2.3 => example.com/fork/net v1.4.5
// こちらは全てのバージョンのx/netを"example.com/fork/net v1.4.5"に置き換える
golang.org/x/net => example.com/fork/net v1.4.5
// こちらはv1.2.3のx/netのみローカルの./fork/netに置き換える
golang.org/x/net v1.2.3 => ./fork/net
// こちらは全てのバージョンのx/netをローカルの./fork/netに置き換える
golang.org/x/net => ./fork/net
)replace directives only apply in the main module’s go.mod file and are ignored in other modules.
replace ディレクティブは、メインモジュールの go.mod ファイルにのみ適用され、他のモジュールでは無視されます。
こちらは例えば以下のようにローカルのnetモジュールに置き換えている場合、実行したメインモジュールでのみ適用され、 ./fork/net側で書かれているreplaceモジュールは無視されるということになります。
// こちらは全てのバージョンのx/netをローカルの./fork/netに置き換える
replace golang.org/x/net => ./fork/net