Merge local Java project to existing git repo - java

I have checked out the source from a git repo, because i was forced to use someone elses svn repo for a while, and now i want to re-check in my source in the original git repo. We are using eclipse (STS) for the project. The perfect solution would be to check in the changes made during this time into a new branch and then putting back together everything.
Does anyone know how I can do this?

If you have your changes made in one folder, you can use that folder as a working tree in order for your git repo to detect and add those changes.
cd /path/to/git/repo
git --work-tree=/path/to/other/repo status
git --work-tree=/path/to/other/repo add .
Then you can commit and push normally from your git repo now updated with the latest changes from the other repo.
Note: that is a command-line solution: once done, you can resume working in Eclipse.

Related

Creating new local git repository from different versions of a java project files

I am new to git, I have many versions of a project stored in my local computer I wish to do the following
create a local repository in git from these versions with differently named root directory
see the differences between the versions
pl. help
Create a new directory, henceforth x, and cd x. Then run git init. This will start a new empty git repository inside the x directory. A git repository is a folder that has a .git subdirectory.
Copy the files from the first version of your project, paste them inside x.
Create a .gitignore file inside x and tell it which files of the project you do not wish be tracked by git. See here for more info.
After you're done, run git add -A to tell git to track all the files in the directory and prepare them for committing (this will add all files except for the ones mentioned in .gitignore).
Now run git commit -m "This is the first version of my project"
Now for the second version - completely overwrite all the files inside x with the files of the second version (by deleting everything except for .gitignore and .git and pasting the files of the second version). Then performs the commands similar to before:
git add -A
git commit -m "Second version of my project".
Repeat these steps for all versions - overwrite files, git add, git commit, repeat.
You now have a local git repository, with each commit corresponding to a version of your Java project.
You can see the differences between the versions using the git diff command or a Git GUI tool of your choice tool which allow you to explore your newly created repository.
You can now also upload your repository to a Git hosting service of your choice (popular ones being Github, BitBucket, GitLab and more) by creating an empty repository inside those services and adding it as a remote in your local repository and pushing the master branch (thus syncing the local copy of the repository with the remote host).
Note that this could be automated if you have a lot of versions, but such automation would largely depend on how your current "folder versioning" is structured, so this is up to you.

Uploading an Existing Maven Eclipse Project into GitHub

There are several examples on StackOverflow and on the web for creating a repository on GitHub and dowloading the repository into Eclipse. Most of these examples are very basic and very old.
I am looking for an up to date and clear step by step example that shows how to upload an existing Maven project from Eclipse to GitHub. The instructions here fail every time.
I thought this would be really easy to do. It has been two hours of frustration. Is there a more elegant solution out there than GitHub?
I would just handle it as it was a normal folder you want to push to GitHub.
So what you basically do is just what Github says if you create a new repo:
Navigate the bash into your folder, then...
git init
git add -A
git commit -m "first commit"
git remote add origin YOUR_GIT_REPO_LINK
git push -u origin master
I think this is the easiest way to do it.
I have modified the instructions found here that kept failing for me.
Go to github create new empty repository
Copy the https URL from github
Go to Eclipse --> Right click on project --> Team--> share project-->
Create new Git Repo.
Go to Git Staging--> Stage all changes --> "Commit" (do not "Commit and Push")
Right click on your Git Repository, select "Push Branch Master"
Paste your https URL of githun which you copy in step 2

How to configure a project imported from GIT to be a Java project in Eclipse?

I've imported a project from Git in Eclipse using this method:
File > Import > Git > Projects from Git > Next > Clone URL .
At this point I inserted the URI like this https://github.com/mygituser/My-Project .
Then my user and password, and the project was imported.
The problem is that Eclipse didn't recognize it as a Java project, and I really don't know why.
As consequence, I can't see errors or warnings on my project and neither use autocomplete, I'm getting this message "This compilation unit is not on the build path of a Java project".
Also, right click on My-Project > Build path shows the message "No actions avaliable".
If you need more information to help me, could you ask me on comments, please?
I appreciate your attention!
Most people don't include build files in repositories, only source. What you need to do is create a new Eclipse project the create a Git repo on top of that:
Create a new Eclipse project, and go to it with your terminal.
git init to initialize a repo.
git remote add origin https://github.com/mygituser/My-Project to add the remote.
git pull -u origin master to pull the changes.
Also, make sure that when you commit, you don't add build files that the author kept out. You can do this via a .gitignore file. Simply take this file and add it to your project directory.
This method applies to most Git repositories, as build and compiled files are usually left out.
Note that this method requires that you install Git for command line (or Git Bash). You can get Git at their website.
Since you already have the source code downloaded from the git repository, you should be able to create an Eclipse project from the existing source code.

Trouble creating Eclipse/Java projects from Git repo

I am brand new to Git and EGit. I have been asked to troubleshoot a project stored in a Git repo located at http://com.myorg.gitrepo/githome/myapp.git.
First I tried just doing this on the Git command-line. From a terminal, I executed:
git clone http://com.myorg.gitrepo/githome/myapp.git myapp
The command was successful and I can now see a project checked out under /home/myuser/myapp (I'm on Ubuntu 14.04).
Now I'm trying to load the checked out project into Eclipse as a Java project. Here are the steps I'm taking:
1. Right-click Package Explorer>> Import >> Git >> Projects from Git >> Next
2. Existing local repository >> Next
3. Select `myapp` project to import >> Next
4. No project found!?!?
As you can see, EGit is looking for some config that isn't there, or perhaps I'm just using it incorrectly.
My questions:
What am I doing wrong, and what can I do to fix this and get the project imported?
How could I improve this process in the future, by using EGit to do the initial clone (bypassing the need to use the raw Git command line)?
Are you sure the project you are importing contains the files eclipse uses for project management?
How does the .gitignore look like? Does it include .metadata/, .project/ for example?
If it does, it means that repo is configured to ignore the configuration files eclipse uses for managing the project, and you should use the wizard to create the project.
I think it is considered good practice to not include any editor specific files in the repos, as these cause a lot of conflicts, and the project shouldn't really depend on the editor like that anyways.

relative path from pom.xml does not get resolved when using git

I have a strange issue which I guess comes from git. In one of the poms in the projects I'm trying to build there's a call to some source-generator with a config-argument like ${project.build.sourceDirectory}/../resources/config/variables.properties (Note the ../ to get to some upper directory). Everything was fine until I merged the master to the branch. This is when the build of this module started to fail with
[ERROR] Failed to execute goal some.package.maven.plugins:runtime-configs-generator:1.1:generate (generate-runtime-config) on project runtime-configs: /home/user/development/workspace_primary/configs/runtime-configs/src/main/java/../resources/config/files.properties (No such file or directory) -> [Help 1]
my setup: I'm locally using git and dcommit to a remote svn repository.
It seems like the file can't be found anymore. Strangely there are no changes in the relevant parts of the files after the merge.
I next tried to merge by using svn just to make sure the files are exactly the same as with the git merge.
Then I commited the merge I did with git to the subversion repository and did a fresh checkout using svn. It builds with no problem. However when using the git repo I still get the same error.
I tried to delete the local git branch and recreated it again from the remote refs. Still it does not build with the error. First I thought it might be an issue with my terminal/shell (terminator with zshell) having a problem with relative paths, but then why it built before the merge and why it builds from the svn checkout but not from the git directory? When I replace the relative path in the pom.xml with something like
${project.basedir}/src/main/resources/config/variables.properties
it also runs from the git directory though.
Can anyone explain this weird behavior, I'd love to understand what I'm missing.
Something must have been broken in the git repo... I restored an older version from a backup, did git svn fetch && git svn rebase and it's working fine now

Categories

Resources