How to ignore replace directive in go.mod

I'm using "replace" statement while do my local development. So my go.mod looks like this:

require (
 gorm.io/gorm v1.21.11
 github.com/mypackages/session v1.1.0
)

replace (
 github.com/mypackages/session => ./../session
)

But I have no need in "replace" when I git commit my changes and deploy code to production, so I need to comment this line of replace code on each git commit and uncomment it then. Is there a way to ignore the "replace" statement on a production environment?


Solution 1:

replace can't be ignored in an environment, because it's used at dependency resolution time, which comes before build, which is long before it ever gets executed in production. But to answer the root question, no, you can't "ignore" the directive. If it's there, it's there.

Solution 2:

While @Adrian is correct in that there is no way to accomplish this in Go, I think this question is less about Go and more about Git. You can ignore a specific part of your file using content filters. See this SO answer for more information.