0

I'm a beginner when it comes to version control. I've cloned a repository and started working on it, also for versioning am using EGit on eclipse because it's much easier.

So my problem is when I try to add the existing local git repository (Git Repositories -> Add an existing local repository to this view) to eclipse it says that no repository found (screenshot below). I think the reason is that he didn't find the .git folder on the project directory, because somehow the .git folder disappears and just after that I faced this issue. Maybe some of you will say that I need just to clone again the project and copy the .git folder and put it on the existing project, but the problem is that the remote project received many commits after my first clone, so can that affect my local project? Thank you :D

click here to display the image

1 Answer 1

1

Clarification about .git folder

Without a .git folder you have not really a git repository! The folder contains all repository data.

So your "repository" is currently only a normal file structure and has lost all git information - it's only the last working copy.

Wanted

As far as I understood, you want to apply your changes to the repository (and maybe later create a PR to origin/remote one...) but you lost the git data completely and you want to fix this.

Suggestion

Maybe you could do following

  1. clone the remote repository to another, new location at your machine
  2. checkout same branch where you formerly did your changes
  3. search for the exact commit id where you started your uncommitted changes (it's important to exactly checkout the same commit as before, so you have no merge problems later)
  4. do a "git checkout $commitNumber"
  5. now create your own branch from this point
    (At this point we are on the same position as when you started your former local changes - means same base)
  6. copy files from your old location (containing your changes) recursively into the new location - but ensure relative pathes do match!
    (so GIT will recognize file changes as diff...)
  7. open your Eclipse IDE
  8. try to add the new location as an existing local repository inside Eclipse
    (this will work now)
  9. open the "Git Staging" view
    Now you should see your delta to your own branch, means your changes.
  10. add your changes to index and commit them to your branch
  11. merge your branch into wanted target main/master branch

IMHO this should solve your problem.

2
  • I think this should work, before that, i didn't understand the 6th step ? what did you mean by copy the old one into the new location? the new location contains the same java file's name and configuration files as the old one .
    – Oncobe
    Commented Apr 17, 2021 at 10:40
  • @Oncobe : I updated the text so step 6 is easier to understand - it just means you copy your former file changes to the new repo (on file system).
    – de-jcup
    Commented Apr 20, 2021 at 12:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.