英文:
Where to initialise git in Go project
问题
作为一个完全的Go初学者,我不确定在哪里初始化Git。
这里的文档https://golang.org/doc/code.html似乎建议在hello目录之外的早期进行初始化,然后稍后告诉我在hello目录内运行git init
。
对此有什么建议吗?
英文:
As a complete beginner to Go I'm not sure where to init
Git.
The docs here https://golang.org/doc/code.html appear to suggest outside the hello directory early on and then later tell me to run git init
inside the hello directory.
Any advice on this would be useful.
答案1
得分: 6
这个例子很清楚:
$ cd $GOPATH/src/github.com/user/hello
$ git init
你在项目'hello'中初始化了仓库。
这样做的好处是:
-
你可以将它推送到你的GitHub仓库(你需要先在GitHub上创建一个空的仓库):
git remote add origin https://<user>@github.com/<user>/hello git push -u origin master
-
你的Go项目可以通过"go get"命令获取:
go get github.com/<user>/hello # 这将在`$GOPATH/src/github.com/<user>/hello`中克隆并编译该项目。
你在hello
目录之外看到的.git
(在同一页上)是另一个项目的:
src/
github.com/golang/example/
.git/ # Git repository metadata
hello/
hello.go # command source
在这里,项目是'example',包括几个包,其中包括'hello'。
英文:
The example is clear:
$ cd $GOPATH/src/github.com/user/hello
$ git init
You do initialize the repo within your project 'hello'.
That way:
-
you can push it to your GitHub repo (that you need to create first on GitHub, empty):
git remote add origin https://<user>@github.com/<user>/hello git push -u origin master
-
your go project is "go gettable"
go get github.com/<user>/hello # that would clone and compile the project in `$GOPATH/src/github.com/<user>/hello`.
The .git
you see outside hello
(on the same page) is for another project:
src/
github.com/golang/example/
.git/ # Git repository metadata
hello/
hello.go # command source
Here, the project is 'example
' and include several packages, including the hello
one.
答案2
得分: 0
你会希望将其初始化到与运行go get github.com/user/hello
时相同的级别,即在hello
目录中。
基本上,如果你初始化了git,将你的仓库推送上去,然后再次运行go get
,不应该有任何变化。
英文:
You'd want to initialize it at the same level as it would have been if you'd run go get github.com/user/hello
- i.e. in the hello
directory.
Basically, if you initialize git, push your repo up an go get
again, nothing should change.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论