简体   繁体   中英

Issue with adding an existing git repository using EGit

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

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.

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