我应该在Home或Eclipse Workspace中存储git存储库吗?

时间:2023-01-17 18:10:44

I'm just moving from svn to git, and am keen to lay some good foundations.

我只是从svn转到git,我渴望奠定一些良好的基础。

By default Eclipse wants to store my local clone repository in ~/git. I'm more comfortable keeping all data for a task in the same workspace - so I'm inclined to keep it in my workspace.

默认情况下,Eclipse希望将本地克隆存储库存储在〜/ git中。我更愿意在同一个工作区中保存任务的所有数据 - 所以我倾向于将它保留在我的工作区中。

Are there any significant pros/cons I should consider?

我应该考虑哪些重要的利弊?

I don't intend doing a lot of branching - I'm really going down the dvcs route mostly to overcome some unreliable internet comms issues.

我不打算做很多分支 - 我真的要走dvcs路线,主要是为了克服一些不可靠的互联网通信问题。

3 个解决方案

#1


26  

I'm too switching to Git in Eclipse, and reading about this issue. It seems that current wisdom (though not everyone agrees) is:

我也在Eclipse中切换到Git,并阅读这个问题。目前的智慧(虽然不是每个人都同意)似乎是:

  • Get used to NOT having your projects below the workspace directory.

    习惯于将项目放在工作区目录下面。

  • Have one git repository for each group of related eclipse projects (and perhaps more files, of course). The concept of "related projects" is up to your convenience [*]

    每组相关的eclipse项目都有一个git存储库(当然也许还有更多的文件)。 “相关项目”的概念取决于您的方便[*]

  • For each repository, one first level directory for each Java project. This implies that you'll have a .git/ directory, and, at the same level, the project directories.

    对于每个存储库,每个Java项目都有一个第一级目录。这意味着你将拥有一个.git /目录,并且在同一级别上有项目目录。

Example: suppose that, "before GIT", you had one eclipse workspace with several projects:

示例:假设“在GIT之前”,您有一个带有多个项目的eclipse工作区:

/wk/workspace/.metadata/  
/wk/workspace/projXXX/  
/wk/workspace/projXXXtest/  (related with the previous)
/wk/workspace/projYYY1/     |
/wk/workspace/projYYY2/      >  three related projects
/wk/workspace/projYYY3/     |
/wk/workspace/projZ/        (a project you are not going to version in git)

Then you'll create two empty directories, one for each repository, say:

然后你将创建两个空目录,每个存储库一个,说:

~/repositories/XXX/ 
~/repositories/YYY/ 

and afterwards, with the new GIT layout, you'll have:

然后,使用新的GIT布局,您将拥有:

/wk/workspace/.metadata/  
/wk/workspace/projZ/ 

~/repositories/XXX/.git/   (XXX related repository - non-bare)
~/repositories/XXX/projXXX/
~/repositories/XXX/projXXXtest/

~/repositories/YYY/.git/   (YYY related repository - non-bare)
~/repositories/YYY/projYYY1/
~/repositories/YYY/projYYY2/
~/repositories/YYY/projYYY3/

Eclipse (EGit) does all this for you when you click Team->Share over an existing project and specify (in the example) ~/repositories/XXX/.git/ as repository, (~/repositories/XXX/ as "Working directory", leave "Path within repository" blank).

Eclipse(EGit)在您单击Team-> Share over a existing project并指定(在示例中)〜/ repositories / XXX / .git / as repository,(〜/ repositories / XXX / as“工作目录)时为您完成所有这些操作“,将”存储库中的路径“留空”。

[*] Bear in mind that here each group of projects is, from the Git point-of-view, just a set of directories inside a repository. Some relevant implications: in the above example, you'll never have in the Eclipse workspace two different branches/versions of projects projYYY1 -projYYY2 simultaneously; and, say, when you tag a project commit, you are actually tagging the full repository (group of projects) commit.

[*]请记住,从Git的角度来看,每组项目都只是存储库中的一组目录。一些相关含义:在上面的示例中,您将永远不会在Eclipse工作区中同时拥有两个不同的分支/版本的项目projYYY1 -projYYY2;并且,比方说,当您标记项目提交时,您实际上是在标记完整的存储库(项目组)提交。

#2


2  

The .git should be where your working tree is (that is the files representing the current HEAD of the current branch you are working on)

.git应该是您的工作树所在的位置(即表示您正在处理的当前分支的当前HEAD的文件)

Remember that with Git, branches are not directories (as opposed to SVN), so your working tree will represent directly a branch content, not several directories (for your various branches), followed by a content per branch.

请记住,使用Git,分支不是目录(而不是SVN),因此您的工作树将直接表示分支内容,而不是几个目录(针对您的各个分支),后跟每个分支的内容。

I usually like to keep my project sources separate from my Eclipse workspace, but that is a matter of preference.

我通常喜欢将我的项目源与Eclipse工作区分开,但这是一个偏好问题。

#3


2  

I think, it is a good idea storing the git version tree outside the workspace. This way it is possible to separate projects from different repositories, but still handle them in the same workspace.

我认为,将git版本树存储在工作区之外是一个好主意。这样就可以将项目与不同的存储库分开,但仍然可以在同一个工作区中处理它们。

Additionally, if you put the code outside the workspace, you can organize your projects hierarchically outside the workspace (in the working copy), but still see the flat representation in Eclipse.

此外,如果将代码放在工作空间之外,则可以在工作空间之外(在工作副本中)分层组织项目,但仍然可以在Eclipse中看到平面表示。

#1


26  

I'm too switching to Git in Eclipse, and reading about this issue. It seems that current wisdom (though not everyone agrees) is:

我也在Eclipse中切换到Git,并阅读这个问题。目前的智慧(虽然不是每个人都同意)似乎是:

  • Get used to NOT having your projects below the workspace directory.

    习惯于将项目放在工作区目录下面。

  • Have one git repository for each group of related eclipse projects (and perhaps more files, of course). The concept of "related projects" is up to your convenience [*]

    每组相关的eclipse项目都有一个git存储库(当然也许还有更多的文件)。 “相关项目”的概念取决于您的方便[*]

  • For each repository, one first level directory for each Java project. This implies that you'll have a .git/ directory, and, at the same level, the project directories.

    对于每个存储库,每个Java项目都有一个第一级目录。这意味着你将拥有一个.git /目录,并且在同一级别上有项目目录。

Example: suppose that, "before GIT", you had one eclipse workspace with several projects:

示例:假设“在GIT之前”,您有一个带有多个项目的eclipse工作区:

/wk/workspace/.metadata/  
/wk/workspace/projXXX/  
/wk/workspace/projXXXtest/  (related with the previous)
/wk/workspace/projYYY1/     |
/wk/workspace/projYYY2/      >  three related projects
/wk/workspace/projYYY3/     |
/wk/workspace/projZ/        (a project you are not going to version in git)

Then you'll create two empty directories, one for each repository, say:

然后你将创建两个空目录,每个存储库一个,说:

~/repositories/XXX/ 
~/repositories/YYY/ 

and afterwards, with the new GIT layout, you'll have:

然后,使用新的GIT布局,您将拥有:

/wk/workspace/.metadata/  
/wk/workspace/projZ/ 

~/repositories/XXX/.git/   (XXX related repository - non-bare)
~/repositories/XXX/projXXX/
~/repositories/XXX/projXXXtest/

~/repositories/YYY/.git/   (YYY related repository - non-bare)
~/repositories/YYY/projYYY1/
~/repositories/YYY/projYYY2/
~/repositories/YYY/projYYY3/

Eclipse (EGit) does all this for you when you click Team->Share over an existing project and specify (in the example) ~/repositories/XXX/.git/ as repository, (~/repositories/XXX/ as "Working directory", leave "Path within repository" blank).

Eclipse(EGit)在您单击Team-> Share over a existing project并指定(在示例中)〜/ repositories / XXX / .git / as repository,(〜/ repositories / XXX / as“工作目录)时为您完成所有这些操作“,将”存储库中的路径“留空”。

[*] Bear in mind that here each group of projects is, from the Git point-of-view, just a set of directories inside a repository. Some relevant implications: in the above example, you'll never have in the Eclipse workspace two different branches/versions of projects projYYY1 -projYYY2 simultaneously; and, say, when you tag a project commit, you are actually tagging the full repository (group of projects) commit.

[*]请记住,从Git的角度来看,每组项目都只是存储库中的一组目录。一些相关含义:在上面的示例中,您将永远不会在Eclipse工作区中同时拥有两个不同的分支/版本的项目projYYY1 -projYYY2;并且,比方说,当您标记项目提交时,您实际上是在标记完整的存储库(项目组)提交。

#2


2  

The .git should be where your working tree is (that is the files representing the current HEAD of the current branch you are working on)

.git应该是您的工作树所在的位置(即表示您正在处理的当前分支的当前HEAD的文件)

Remember that with Git, branches are not directories (as opposed to SVN), so your working tree will represent directly a branch content, not several directories (for your various branches), followed by a content per branch.

请记住,使用Git,分支不是目录(而不是SVN),因此您的工作树将直接表示分支内容,而不是几个目录(针对您的各个分支),后跟每个分支的内容。

I usually like to keep my project sources separate from my Eclipse workspace, but that is a matter of preference.

我通常喜欢将我的项目源与Eclipse工作区分开,但这是一个偏好问题。

#3


2  

I think, it is a good idea storing the git version tree outside the workspace. This way it is possible to separate projects from different repositories, but still handle them in the same workspace.

我认为,将git版本树存储在工作区之外是一个好主意。这样就可以将项目与不同的存储库分开,但仍然可以在同一个工作区中处理它们。

Additionally, if you put the code outside the workspace, you can organize your projects hierarchically outside the workspace (in the working copy), but still see the flat representation in Eclipse.

此外,如果将代码放在工作空间之外,则可以在工作空间之外(在工作副本中)分层组织项目,但仍然可以在Eclipse中看到平面表示。