No projects found while importing project from GIT - java

i am facing problem in importing project from github i.e,remote repository.it is giving no project found.and found the reason i should push .project and .classpath files also then only it will recognise the java project.but how to push them.
and i have 1more question
can i push more than 1 project into the remote repository.
i used following commands to push into the repository
git add .
git commit -m "intial commit"
git remote add swathi "https://github.com/swathiananthula/samplerepo.git"
git push swathi master
can anyone help me?
how can I import the project successfully into STS.

Remove .project and .settings entries (or any project config) from the .gitignore file and use git add . and git push.
The next time someone clones your repository they would be able to import it as a project.
Just note that though if you check in project files, make sure you don't have machine specific entries in your project settings as it will differ for each developer. This includes any classpath entries with full paths etc.
For your initial question; yes you can have multiple projects in one repository, though many would not recommend it.

Related

After adding Maven framework support in IntelliJ, it moved all /src/com/... files into /src/main/java/com/... without updating git history. How fix?

I added Maven support to a project that previously did not have it. IntelliJ then moved all the java files, but even though it's a git project, did not use git mv and so there's no file history.
How do I fix this?
Example:
//The below structure was before Maven
/src
.../com
.../test
.../SomeClass.java
//After Maven
/src
.../main
.../java
.../com
.../test
.../SomeClass.java
Renames are not first class citizens in Git.
Git detects renames based on file content changes.
As such, the main purpose of git mv is to simplify staging.
If files get renamed without git mv,
that causes only a minor inconvenience,
which you can rectify by appropriate git add commands.
That is, for each renamed file, one git add for the old name ("deleted file" from the perspective of Git), and one git add for the new name ("new file" from the perspective of Git).
In your particular example,
a simple fix could be staging everything by running git add . at the project root.
After that, check the output of git status -sb.
There's a good chance that Git will figure out all the renames.

How to ignore library project from Git pull?

I am a newbie in dealing with Git. I am using Git in eclipse.
My main project contains the google-play-services_lib has a library project.
Recently I did Git -> Fetch from remote repository and now when I do Git -> Pull in main project, I get conflicts in google-play-services_lib which I never changed (generated files changes).
I want to ignore the library project changes from Git pull in eclipse.
Whenever I take Git pull from main Project, I always get the following conflict in eclipse-
Checkout conflict with files:
google-play-services_lib/bin/AndroidManifest.xml
google-play-services_lib/bin/R.txt
google-play-services_lib/bin/google-play-services_lib.jar
google-play-services_lib/bin/jarlist.cache
So though these conflicts are system generated changes, I always want to ignore them.
I used Team -> Disconnect on google-play-services_lib, but this only disconnected me from Git for the library google-play-services_lib.
I used Team -> Ignore on google-play-services_lib, but this did nothing in resolving conflicts.
I used Team -> Untrack on google-play-services_lib, but this added all files in google-play-services_lib in the conflict state.
Try the Options Assume unchanged and Assume changed:
Assume Unchanged to all of the generated files
Pull
Assume Changed to all the generated files
Because this will get very annoying if you have to do it for every commit, you could write a Script to handle this. The required commands are:
git update-index --assume-unchanged <file>
git update-index --no-assume-unchanged <file>

Git Eclipse import source folder into project

I have a bit of an issue that I can't seem to find a solution to.
I had a project in eclipse that I was working in. I have a remote git repo in which all the source files are backed up to (but it doesn't seem to be the entire project). My project got deleted in eclipse but I had previously had a backup of the entire directory that I had zipped up and emailed to myself a while back which contains the entire project including external libraries etc that I need for the project.
I can import the zipped project into eclipse but obviously the source directory is out of date. I need to be able to pull from my existing repo all the changes I made to my source files. I was able to use the Restore From Local History from the context menu in eclipse which brought in all my changes up until my last push.
Is there a way to re-link this newly create project with my existing repo so all my original commits are available to the new project? Or is there a way to get my source files from my repo into the newly created project. I'm not sure how to proceed and I don't want to make any further changes until I get this resolved.
Any help would be greatly appreciated.
Depending on how you restored the other files, you might run into merge conflicts once you pull from your remote repository. Make sure to make a backup first.
Eclipse:
In the context menu of your Eclipse project, you should see the entries
Team -> Remote -> Configure Fetch from Upstream / Configure Push to Upstream
There you can configure where to fetch from, and where to push to, respectively.
Once you have configured the URI to your remote repo, you might want to use the Dry-Run button to check that it is linked correctly.
Command line:
You can also use the command line to organize your remote repositories.
Navigate to your project and run
git remote
to get a list of your remote repositories.
If that list is empty, you can use
git remote add <remote-name> <your-remote-repo-url>
to add a remote repository. So, e.g.
git remote add origin https://github.com/yourUsername/yourRepo
Then you should be able to pull from your remote as usual.
Alternatively, you could follow this guide to import the remote repository as a new project. This will bring back the source code in its current state in the remote repository.
But you mentioned that the remote repo does not contain the whole project. So you would probably have to add all files manually from your restored project that were not tracked by the git repository.

Eclipse setup for git project

There are quite a few questions on this topic, but there are no satisfactory answers unitl now, e.g this.
I'm using Eclipse Kepler (20130529-2219), with ME2 (1.4.0.20130601-0317) and Eclipse Git Team Provider (Java implementation of GIT 3.0.0.201306040240-rc3). So I started with great expectations after reading how great git is.
Firstly, I opened an existing project and removed all the .svn rubbish and commited it to a local git repository. Perfect - now it is time to push the files to a remote repository. After having some problems creating the known_hosts file on Windows the push was successful.
Now the problems started: I wanted to pull changes for the repository, but "... not configured for pull". OK, here it was discussed that this is a common issue, and you have to delete the project and then reimport it from a remote server to allow pulling.
Hence, I set up everything again and pulled the project. Until now I was always told that .project files should not be commit to version control, therefore I didn't include them. The "import -> import from git -> local"-menu does not recognize the files in the repo as a Java project. I can therefore only import the project as a general project or use the project wizzard and set up a new Maven project, which is stupid because all information already exists in the POM.xml. If I do a plain project import, Eclipse does not know that it is a Java or Maven project and throws tonnes of errors.
Question (skip detailed problem): Is there some less awkward way to import a Maven and Java project from a remote git repo when no .project file exists?
Easiest solution: do include the .project (as in this answer) in your git repo.
And do include also the .classpath, since you now can reference relative paths in it, instead of absolute path: see ".classpath and .project - check into version control or not?"
I found an alternative to keep .project file out of Git version control. As you said the pom.xml file should be enough for IDEs to figure out that a maven project it´s in place (and it is).
Let's say you have pushed your project into Git (without .project file) and now you want to import that project into Eclipse.
Make sure you have the Git repo added into Git perspective
Go to J2EE Perspective and double click on an empty space on Navigation View. Import -> Existing Maven Projects
Browse to your Git repo location and voila! Eclipse should catch all pom.xml files and determinate they are independent Maven projects
In my case this worked to pull multiple projects located at one same Git repo, each of them only storing pom.xml file (and no .project at all)

How to add eclipse project to existing git repo?

I already have an existing project in Eclipse that I want to add to my team's github repo. The github repo is empty right now. What's the best way to add this project to our github repo? I was thinking of git cloneing our repo into the workspace folder (parent to the project in question) and then adding the project files using git add, then pushing the changes. Would that work, or is there a better way to do this (perhaps with EGit)?
You have to add a remote to the project, and then push to it.
For example, you can do (from inside the project directory)
git init # if you haven't already
git remote add origin ssh://git#github.com:.....
git push -u origin master
there should be a way to do that from the eclipse plugin too, but I find it easiear to do it from the command line.. :)
By the way, remember to add all the IDE-specific files to .gitignore, to avoid pushing garbage to the world: they usually are .project, .classpath and directories like bin/*,.settings/* ...

Categories