Jason
Jason

Reputation:

EGit and Eclipse... how to add a new .java class from Git Repo View?

Since git moved my project to be under its own /git/ directory, I have lost the ease of use of things like right clicking in the project and choosing things like 'New' -> 'Java Class'. The source folder, Package and Superclass fields are blank by default when I try this from the Git Repositories View, whereas in Package Explorer View I would still be able to this, except git moves your project out from there. (Now that I write it out, could this be a path issue?)

Adding pictures to help explain :

This is what I get when I right click in an attempt to add a class in the git version of my project:

enter image description here

This is what I get when I attempt to add a class in the project explorer version of my project:

enter image description here

Upvotes: 2

Views: 6536

Answers (3)

Adindu Stevens
Adindu Stevens

Reputation: 3567

Adding new files from eclipse project to your git repo is quite simple with EGIT plugin. Egit comes pre-installed in every Eclipse installation that was shipped for Java EE and you can install from eclipse market place if you don't alraedy have it. To Add a new file to your git repo, follow the following steps

  1. Add the new file like you would normally do in eclipse(A white question mark will appear on the new file indication that it is not available for synchronization yet).
  2. Right click the new file and hover the pointer on Team, then click Add To Index. Once it is added to index, it is ready for committing.

    To Commit

  3. Right click on the project, select Team.

  4. Click Commit and push (You will reaslize that the new file is now available as a Staged File.
  5. Enter a commit Message and then click commit and push.

Upvotes: 0

Hunt3r
Hunt3r

Reputation: 1

If you are using Linux then you can add any file by following these simple steps :

  1. Move the file you'd like to upload on the github into the local directory that was created when you cloned the repository.
  2. Open the local repository on you terminal(path).
  3. git add .
  4. git commit -m "file to be added"
  5. git push origin

Upvotes: 0

VonC
VonC

Reputation: 1323553

The EGit User guide mentions:

When setting up Git Repositories with EGit, there are two recommendations for the creation of "productive" (as opposed for "playground") Repositories:

  • Don't create the Repository within the Eclipse workspace:
    • Be careful when cloning or creating a Repository
    • Make sure to use the Git Sharing Wizard correctly
  • Don't create a Repository with an Eclipse project as root
    • Make sure to use the Git Sharing Wizard correctly

The first one happens when you specify a workspace folder during cloning or creation of a Repository.

Both of the above will happen when you use the Git Sharing Wizard from an Eclipse project that you have created manually in your workspace without taking precautions (the wizard has been fixed in the latest version).

This is compliant with the workaround found by the OP jason:

I did not create the repo in the Eclipse workspace (its in /git/).
I did find a 'workaround' of sorts.

Instead of importing a project from the workspace:

  • create the repo in /git/ first,
  • then create a new project in there.

This made it so Package Explorer was able to do its thing, and Git Repo View was able to do its thing to

Upvotes: 1

Related Questions