Search code examples
gogo-modules

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

  • 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.