Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: mod tidy removes replaced go.sum entries #31190

eliasnaur opened this issue Apr 1, 2019 · 2 comments

cmd/go: mod tidy removes replaced go.sum entries #31190

eliasnaur opened this issue Apr 1, 2019 · 2 comments


Copy link

@eliasnaur eliasnaur commented Apr 1, 2019

What version of Go are you using (go version)?

$ go version
go version devel +b9b01ed56f Fri Mar 29 12:18:07 2019 +0100 linux/amd64

Does this issue reproduce with the latest release?


What did you do?

I have a repository with two submodules, a library module and a main module depending on the library module. For convenience when working on both modules at the same time, I want to use a replace directive to point to the local path of the library. It's described in

replace also can be used to inform the go tooling of the relative or absolute on-disk location of
modules in a multi-module project, such as:

replace => ../foo

I plan to check in the replace directive to the project repository, because it will be ignored by external modules importing main.

However, running go mod tidy when the main module contains a replace directive, the go.sum entries disappear:

$ git clone
Cloning into 'gomodtidy'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 2), reused 17 (delta 2), pack-reused 0
Unpacking objects: 100% (17/17), done.
$ cd gomodtidy/main/
$ cat go.sum v0.0.0-20190401155538-6de8c4f5b51e h1:CgKA/cdZwECjX9i6bSRVHgjDA1Ik1xAKy86Fdm7lxU8= v0.0.0-20190401155538-6de8c4f5b51e/go.mod h1:1/0i90HQ12RlIgzNk8GUdrWv8IQQA5d5dmJpmNqvLJo=
$ go mod edit -replace
$ go mod tidy
$ git diff
diff --git a/main/go.mod b/main/go.mod
index 2f5d4cb..bd0502c 100644
--- a/main/go.mod
+++ b/main/go.mod
@@ -3,3 +3,5 @@ module
 go 1.13
 require v0.0.0-20190401155538-6de8c4f5b51e
+replace => ../lib
diff --git a/main/go.sum b/main/go.sum
index c537139..e69de29 100644
--- a/main/go.sum
+++ b/main/go.sum
@@ -1,2 +0,0 @@ v0.0.0-20190401155538-6de8c4f5b51e h1:CgKA/cdZwECjX9i6bSRVHgjDA1Ik1xAKy86Fdm7lxU8= v0.0.0-20190401155538-6de8c4f5b51e/go.mod h1:1/0i90HQ12RlIgzNk8GUdrWv8IQQA5d5dmJpmNqvLJo=

What did you expect to see?

The go.sum lines were kept for the lib module.

What did you see instead?

go mod tidy removes the replaced module's go.sum lines. The lines are technically not used, but will be when the main is not the main module, e.g. someone imports


This comment has been minimized.

Copy link

@bcmills bcmills commented Apr 1, 2019

Dup of #29182.

@bcmills bcmills closed this Apr 1, 2019

This comment has been minimized.

Copy link

@bcmills bcmills commented Apr 1, 2019

(Also note that go.sum entries outside of the main module are currently ignored; see #28802.)

@golang golang locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.