在Go项目中初始化git应该在哪里?

huangapple go评论87阅读模式
英文:

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://&lt;user&gt;@github.com/&lt;user&gt;/hello
      git push -u origin master
    
  • your go project is "go gettable"

      go get github.com/&lt;user&gt;/hello
      # that would clone and compile the project in `$GOPATH/src/github.com/&lt;user&gt;/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.

huangapple
  • 本文由 发表于 2015年4月16日 04:34:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/29660362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定