简体   繁体   中英

Workspace and repo paths arrangement for eclipse and git

I've seen similar questions but some are very old and some are not quite what I'm looking for or have no answers.

I have projects in Eclipse under /workspace/project1 and /workspace/project2 . They are Gradle projects and are dependent on each other. I also have /workspace/project3 which is a Gradle project but independent.

I need to "upload" them to a git repo on Bitbucket. I installed EGit to help me with this. It asks me where my local repo is located and I don't know what to tell it. Should I create a repo per workspace or per group of dependent projects or what?

For example when I right click a project and press Team > Share > Git I get to this dialog and I don't know what I should fill in there.

在此处输入图片说明

A few things to understand/keep in mind:

  • An Eclipse workspace is a logical container of projects, not necessarily a physical container. The folder in which a worksapce is located can also be a physical container of projects, meaning the project's files can be located in a folder under the workspace folder (this is the default location if you create a new project in Eclipse). But that is not a requirement; a project that is contained within a workspace can have its contents (its files) located in any location on your file system.
  • In most dev setups, the local git repos are located in a "standard" location in the user's home directory, namely %USER_HOME%/git/name-of-repo . Again, that's not a hard requirement, users have the option to clone or create repos in any location they choose.

So Eclipse eGit is showing you those 2 axes of flexibility. It's asking where you want to create your local git repo, which usually is different than your workspace folder. Use the Create... button to create it. I think at that point it will auto-populate the Path within repository field. If it does not, you can name that path anything you want (usually its the same as the project name, though not necessarily)

At the end of it all you'll have your workspace (logical container) as well as a local git repo which will be the physical location of the project contents.

Each ( non-bare ) git repository has a work directory in which the files of the currently checked out commit (referred to as HEAD ) are stored.

By default, the work directory is the parent of the git metadata directory (named .git ), but it can be detached through a config setting . For example: git config core.worktree /path/to/workdir

EGit cannot deal with repositories that have a detached work directory as answered here: EGit working directory not under the local repository

But irrespective of this limitation, you cannot split the work directory of a git repository among several workspaces.

Therefore, you should move the projects to the work directory to resemble this structure:

~/git/my-repo/.git
~/git/my-repo/project1
~/git/my-repo/project2
~/git/my-repo/project3

If project3 is independent of the others, it may remain where it is or be located somewhere else entirely.

A word of caution when planning to have interdependent projects spread across several git repositories. This makes the git repositories effectively interdependent as well, but without git having a dependency management tool.

To have EGit move the projects, you would enter project1 in the Path within repository input field.

Commonly used build files like the master pom.xml or corresponding Gradle files would be located in the root of the work directory. This also eases configuration of popular build services like Travis, Codeship and friends.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM