Created
November 8, 2018 21:40
-
-
Save myitcv/3c4b93d2393214ee609185ec70198d9f to your computer and use it in GitHub Desktop.
Creating submodules in a single commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir -p /home/gopher/scratchpad/submodulestest | |
$ cd /home/gopher/scratchpad/submodulestest | |
$ git init -q | |
$ git remote add origin https://github.com/go-modules-by-example-staging/submodulestest | |
$ go mod init github.com/go-modules-by-example-staging/submodulestest | |
go: creating new go.mod: module github.com/go-modules-by-example-staging/submodulestest | |
$ mkdir b | |
$ cd b | |
$ cat <<EOD >b.go | |
package b | |
const Name = "Gopher" | |
EOD | |
$ go mod init github.com/go-modules-by-example-staging/submodulestest/b | |
go: creating new go.mod: module github.com/go-modules-by-example-staging/submodulestest/b | |
$ go test | |
? github.com/go-modules-by-example-staging/submodulestest/b [no test files] | |
$ mkdir a | |
$ cd a | |
$ cat <<EOD >a.go | |
package main | |
import ( | |
"github.com/go-modules-by-example-staging/submodulestest/b" | |
"fmt" | |
) | |
const Name = b.Name | |
func main() { | |
fmt.Println(Name) | |
} | |
EOD | |
$ go mod init github.com/go-modules-by-example-staging/submodulestest/a | |
go: creating new go.mod: module github.com/go-modules-by-example-staging/submodulestest/a | |
$ go mod edit -require=github.com/go-modules-by-example-staging/submodulestest/[email protected] -replace=github.com/go-modules-by-example-staging/submodulestest/b=../b | |
$ go run . | |
go: finding github.com/go-modules-by-example-staging/submodulestest/b v0.1.1 | |
Gopher | |
$ go list -m github.com/go-modules-by-example-staging/submodulestest/b | |
go: finding github.com/go-modules-by-example-staging/submodulestest/b v0.1.1 | |
github.com/go-modules-by-example-staging/submodulestest/b v0.1.1 => ../b | |
$ git add -A | |
$ git commit -q -am 'Initial commit' | |
$ git push -q | |
remote: | |
remote: Create a pull request for 'master' on GitHub by visiting: | |
remote: https://github.com/go-modules-by-example-staging/submodulestest/pull/new/master | |
remote: | |
$ git tag b/v0.1.1 | |
$ git push -q origin b/v0.1.1 | |
$ git tag a/v1.0.0 | |
$ git push -q origin a/v1.0.0 | |
$ cd $(mktemp -d) | |
$ export GOBIN=$PWD/.bin | |
$ go mod init example.com/blah | |
go: creating new go.mod: module example.com/blah | |
$ go get github.com/go-modules-by-example-staging/submodulestest/[email protected] | |
go: finding github.com/go-modules-by-example-staging/submodulestest/a v1.0.0 | |
go: finding github.com/go-modules-by-example-staging/submodulestest/b v0.1.1 | |
go: downloading github.com/go-modules-by-example-staging/submodulestest/a v1.0.0 | |
go: downloading github.com/go-modules-by-example-staging/submodulestest/b v0.1.1 | |
$ $GOBIN/a | |
Gopher | |
$ go version | |
go version go1.11.2 linux/amd64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment