Can I reimport a deleated .git file without loosing code? - java

I deleted my .git file from my project. But, I haven't deleted my project folder. Can I still import ONLY .git file without reimporting the whole project?
I haven't tried anything I don't want to lose the code I have when deleting the folder and reimporting the complete project

To recover a file/folder from your system you need to look for some recovery tools.
But here is the steps, how you can save your uncommitted effort safely:
1- clone your project into another folder.
2- you will have the latest code with .git stuffs.
3- copy paste all files from old folder to new.
4- now you have overwritten only those files which are having change.
5- run git status to see the efforts intact.
Alternatively:
1- clone your project into another folder.
2- you will have the latest code with .git stuffs.
3- copy paste all .git stuffs from new folder to older.
4- now you have git back into your project.
5- run git status to see the efforts intact.

.git is the directory which maintains the version control for your source code. Delelting this does not affect to your source code + local changes.
If you need the git version control back again, easiest thing you could do is get a fresh clone of the remote repository and use a merging tool(ex:winmerge, araxis merge) from which you can identify your local changes) and then you can do a commit

Related

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
clone the remote repository to another, new location at your machine
checkout same branch where you formerly did your changes
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)
do a "git checkout $commitNumber"
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)
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...)
open your Eclipse IDE
try to add the new location as an existing local repository inside
Eclipse
(this will work now)
open the "Git Staging" view
Now you should see your delta to your own branch, means your changes.
add your changes to index and commit them to your branch
merge your branch into wanted target main/master branch
IMHO this should solve your problem.

Creating a new root directory in an Eclipse project under version control

I'm working on a group project for my software engineering course, and my professor has indicated that I set up the directory structure incorrectly on Github. I'd like to correct the issue now to avoid a grade penalty, but I'm very new to using Git. Basically we have a structure that is as follows on Github.
src
--main
----java
------Source Files
--test
-----java
------Test Files
Various Ivy/Ant build files
.classpath
.gitignore
.git
.project
README.md
I need to create a new directory called CodeComp that will contain the directory structure above except for the README.md, which should be on the same level as the CodeComp directory.
Since our grade is dependent on the commit history, this would need to be preserved. Is there an easy way to do this or are we better off just taking the small deduction on the final project grade?
UPDATE:
In case anyone else has to do this in the future:
Go to the folder holding the project and create the new directory.
Move all files needed into the new directory except .* files. Refresh Eclipse.
Commit and Push the directory changes to the repo regardless of Eclipse errors.
Manually delete the .classpath, .gitignore, and .project files from the repository.
Back-up your .classpath and .gitignore files. Delete your local copy of the repo and re-clone it.
Import the Git project and choose to put the project files in your newly created directory.
Copy the .classpath and .gitignore you backed up into the new project directory. Push the changes.
In theory you should be able to use a standard file browser to move everything but your .git and Readme file into your new sub-folder and then commit that.
The git history will still there but it may see it as two separate files, one that has been deleted and one that is just created. In my experience Git doesn't really like moving files.
In any case, you commit history will still be in the repository, it will just be 2 separate sections from when you moved the files.
But, hey... It may pay to show that move anyway. I know for sure that I was moving files all around when I first learnt about version control. It's all learning.
EDIT: You can test this by committing the change locally and checking the history before you push it upstream to Github.

SVN Ignored folder shows again and again

I have a local SVN folder which has many files/directories/sub-directories
One of them is Project-Ear, which contains generated folders/files that I do not wish to check-in at all..
I have marked this Project-Ear folder as "unversion and add to ignore list"
Now every time, I do SVN Commit, this folder Project-Ear and it's files show in the Commit dialog.
How do I fix this? I do not want this Project-Ear to be shown at all.
If the files were initially committed into the repo, you will need to commit the "un-version" part, at that point they will be removed from the repo, and ignored from then on local file systems.

Git create a subfolder

I've just started to use Bitbucket, but I've the same problem on Github. I'm using Eclipse with EGit.
My problem is when I commit and push: I don't see directly "src" but there's a folder and it's in: https://bitbucket.org/Knux14/screenup/src/
Instead of having my src folder, I need to click on "ScreenUp" first, and then I can see src.
Did I make a mistake on pushing?
You simply added the folder containing your whole project to Git, so now all your stuff is in the subfolder ("ScreenUp").
You can keep using it like this, that's no big problem. But if it bugs you, just remove the repository and remove the project from version control (Google will help), and add it again.

How to commit project into trunk from Eclipse (via Subclipse)?

I have a project in Eclipse, MyProject/, that I want to share and import into my SVN repo:
MyProject/
src/
dist/
lib/
...etc.
Ultimately, I want to end up with an SVN repo for this project that looks like this:
svn://mySVNrepo/
MyProject/
trunk/
src/
dist/
lib/
branches/
tags/
But when I right-click MyProject and select Team >> Share, and follow the prompts, I end up with:
svn://mySVNrepo/
MyProject/
src/
dist/
lib/
So it's: (1) not allowing me to create trunk, branches and tags dirs, and (2) not allowing me to "nest" my imported project into trunk.
I then tried to create the directories manually from the SVN Repo Explorer view, and created:
svn://mySVNrepo/
MyProject/
trunk/
branches/
tags/
Then, I tried to share my project at:
svn://mySVNrepo/trunk
When I try to run this initial import, I get a warning from Eclipse:
Warning: The specified folder already exists in the repository. If you continue, that folder will be checked out to your local workspace and your project will be connected to this existing location. Do you want to continue?
I don't want to overwrite my local copy (that I'm trying to share); it has a lot of work in it!
I don't really understand what this warning is telling me, and basically I don't want to mess anything up!
So I ask: is my approach wrong, and if so, how can I commit my project for the first time into a trunk/ subdirectory? And if my approach is correct, then please help me decipher this warning message and advise on what I should do. Thanks in advance!
One approach that would work is to keep your manually created trunk/branches/tags directories in SVN. Check out the empty /trunk into a parallel directory on your local workstation (Let's say directory #2, with your local project as #1). Then copy your project + code from #1 into that /trunk directory and commit to SVN.
Then you can make a 3rd directory locally, and check-out your SVN copy and ensure it compiles/runs properly. If so you can delete the intermediate #1/#2 directories, or keep your initial project as a backup just incase (but it'll be non-versioned). Then continue to use directory #3 as your new SVN monitored workspace.
If I'm unsure how my changes will affect work that I don't want to lose, I try to take an approach like this so the least amount of harm is done to my code if something goes wrong (say with a SVN command/operation I'm unfamiliar with, etc).
From the menu, select Window > Open Perspective > SVN Repository Exploring
Right click your repository > New Project Structure > Single project or multiple projects layout > enter 'MyProject' for the Name. This will create the new project with the /trunk/branches/tags/ project structure.
Once it's created, right click the Project and select Checkout.
'MyProject' should now be in your Navigator View. From there you can copy your /src /dist and /lib folders into 'My Project' trunk folder.
Right click your Project and select Team > Commit.
EDIT:
You can also try the Subversive plugin for Eclipse. This plugin has an easier way to share your existing projects to svn as a multiple project layout (trunk/branches/tags folder structure).
I posted the steps in a similar thread.
After one hour of trial and error, I just did the following:
Share it to a wrong folder
Go into the SVN explorer and rename the folder (with src etc.) to trunk
Move that trunk to the correct location (e.g. Project/trunk) in svn
Got into the Project Explorer in Eclipse, right click on the project, team, switch and select the new trunk.

Categories

Resources