git rm -f after add, before commit, on windows cmd line. Was open earlier in STS (Eclipse). Can recover? - eclipse

I wanted to unstage files (as my .gitignore was not set up to ignore some of my IDE files) but in hurry did :
git add w3
//got some .settings etc folder and files added, in newly added sub folder w3
//the repo here already had sub folders w1 & w2.
Then issued:
git rm -f w3/*
I'm on windows 8. The files are hard deleted (not in the recycle bin). Any thing I can do with git or any other (free) way?
Edit Add
* Also it was opened in STS(eclipse) but now deleted the pom, settings everything. Anyway to restore from within eclipse?

Un-commited but added files are still in a repository for a while, however it would be quite tricky to restore it especially for a large old repository as usually it has a lot of garbage. So, if you don't mind dig into garbage, start with git fsck and look for dangling blob.
However, seems you cannot restore names of lost files, only content.

If the file was not versioned you can't restore it. See the documentation of git-rm. See here for how to undo adding a file to the staging area.
If the file was versioned you can retrieve it from a past commit. See this answer for more information.
Of course if you back up your drive you might be able to restore it with your back up program. For that you might get help over at SuperUser.

Related

How to remove a specific directory from GitHub using Eclipse

I've looked all around for a few days now trying to figure this out because our .gitignore even though it lists /bin/ folder it still keeps freaking commiting the whole folder and its getting annoying.
Now we have a whole bunch of crap in a /bin/ folder in our GitHub repository and I have no idea how to remove it. I've tried looking at other peoples examples but they keep talking about a shell command that I don't have in eclipse (or at least don't know how to access)
The sad news is that if a file has been already committed to GitHub, git will continue to version that file.
This means if I commit the entire bin/ then add it to .gitignore, the files will still persist in GitHub. And, if these files in bin/ change, they will also be pushed in the commit because they are versioned.
Luckily, you can remove files and directories from GitHub completely. You need, though, to get to a command line running git. If you have the GitHub application installed, that probably means you have git.
Open command prompt in Windows or Terminal in Mac OS.
Navigate to the directory (ie. cd ~/Workspace/Project) and run the following:
git rm bin/* -f
git commit --amend
git push -f
This should work. Check out this article on the GitHub that also outlines the process.
Hope this helps you!
Disclaimer: always make sure you do your research before working with git. If you have various branches / other complicated stuff going on, this process might be different

Subclipse SVN first commit ignore certain directories

Decided to take the jump from CVS to SVN.
I setup a new repository in subclipse for my project. When I go to 'Finish' the setup it wants to do an initial commit and presents me with a flat list of files to select the files for version controlling.
The problem is I have thousands of generated binary files I dont want to commit.
So I click on cancel because it would take me all day to go through and unselect all the unwanted files. Annoyingly when I click on a parent category for the files I want to ignore it is not recursive!
So I click cancel then go to the eclipse directory structure for the project and manually set svn:ignore on all directories I want to ignore. Then I try and do a commit again and all the files are once again presented - ignore seems to have done nothing.
Can anybody point out what I might be doing wrong?
For the first commit, I recommend writing a small script to delete (of course you'll have a backup) all the files that are not meant to be committed.
Afterwards, if you find you accidentally committed a file, you can
svn delete file
Upon the first checkout, copy back (or better yet, regenerate) all the binary files. This will trigger svn to notice that your local repository is out-of-sync with the remote repository.
cd <Root of local repository>
svn status
You will see lots of "to be added" items. Go to the parent directory and add in svn:ignore properties for each of the generated items.
cd build
svn propedit svn:ignore .
which will open an editor (if it doesn't, you need to set the environmental variable SVN_EDITOR to a suitable editor). Then you can add in entries that svn will know are not tracked.
(in the ignore property editor)
target
build
image*
*.o
(and so on)
Save the file, and it will be staged for the next commit. Subsequent runs of svn status will no longer show these files as "needing to be added", but they will show the directory as "needing to be committed (it's a revision on the directory)"
Quick Aside
So I'm not entirely certain exactly which functionality of Subclipse you were using in order to create a repo and share a project to it, I'm assuming you created like a file based repo through the eclipse SVN repo view and tried to share and then commit to it. It looks like your problem got solved but I did want to add an answer on here because I ran across this post looking for the answer to this same problem of handling initial commits even just in general with SVN and wanted to offer help to anyone else looking for the help.
Intro
To start off I would recommend not working through an IDE extension like this just for the initial commit as they can miss a lot of the options for handling opening a repo in SVN. I personally really like the command line form of SVN to work with but TortoiseSVN is a good option for a GUI.
Whether you create a local file-based repo or are connecting to an SVN server and you want better control over your first commit in an previously unversioned project here is what I've found as the best general workflow for doing so.
Create the remote folder to save to.
On command line this will be:
$> svn mkdir your-url-scheme://your-site-address.domain/path/to/repo/example-directory
Or on TortoiseSVN open your repo for browsing, right click, and select "create new folder"
This will give you a location in the SVN repo to checkout from for our next step.
Checkout in to the already started project
Make sure to use the empty, newly created folder in your repo to checkout with. SVN does not actually require a folder being checked out to to be empty, which is an important part of what makes it actually very flexible and able to subsume parts of your directory into it fairly easily if used correctly.
Now you will checkout this empty folder into the root folder of your already started project. This will add your project to the working copy of this folder without any commit being made yet. The command is:
$> svn co your-url-scheme://your-site-address.domain/path/to/repo/example-directory /your/projects/root/
"co" standing for checkout. In Tortoise svn you can right click on or in the empty repo folder and select "checkout..." and then select the project root.
Set ignores and commit
Finally, you can easily set your ignores on certain files before adding any other files to the tree using the command:
$> svn propset svn:ignore file-or-directory-to-ignore
And to add all non-ignored directories and files:
$> svn add * --force
The force is technically unnecessary in this case but ensures full recursion. You can also now do all of this in your file explorer if using TortoiseSVN or you can even use your IDE extensions to do this at this point(make sure to ignore all files you need to before mass-adding files for commit), all that's left is to make sure to commit the newly added files to the repo and you're up and running with source control :)
Added this method here simply because this method allows you to avoid any unnecessary copying of those stinky binaries that no one wants to lug around with them.

Atlassian Sourcetree + GIT + Mac + Mountain Lion + Eclipse + Android project = failure mode

Using the combination of tools in the title, when I check out a branch, SourceTree/GIT will:
Definitely NOT delete folders from the previously checked-out branch, so if I have BRANCH-ALPHA with FOLDER1 and FOLDER2 and then I check out BRANCH-BETA which has FOLDER2 and FOLDER3 only and no FOLDER1, the resulting structure in FINDER will show that FOLDER1 is still there. Can reproduce this over and over.
Often will not even overwrite files from the previously checked-out branch, so that I'm still seeing BRANCH-ALPHA in Eclipse when I have checked-out BRANCH-BETA.
I close Eclipse before doing the checkout, and then open Eclipse, CLEAN and BUILD everything. It's really a problem with GIT.
The only "solution" is to delete all the folders and all the metadata and then check out the branch. This typically leads to a few hours of trying to "convince" Eclipse to open the project, creating a new workspace, new metadata, etc., and then fixing a lot of things like paths etc.
Any ideas on how to further research the cause and find a solution are very much appreciated.
Git only deletes empty folders when checking out a new commit. You might see apparently empty directories because there are hidden files stored in them. If you try to monitor the behavior by opening them in Finder, you're actually causing the problem since Finder creates hidden files to track the way the folders are displayed.
Does it really bother you that the folders are there? You could add a post-checkout hook that runs git clean -dxf after each checkout; this will remove all the files that are not known by git. Be careful that it will also delete compiled classes, so a new build will be required.
Another possibility is that something is locking files or directories, so git can't remove them while they're still opened/locked by the other program. This would also explain why some files aren't updated to the right version. Does git complain when you switch branches? It should if there's indeed a lock on the files.

Eclipse Git plugin - remove file from repo without deleting local

Using the Egit plugin, is it possible to permanently remove a file from source control without deleting the local copy?
I.e., is there a GUI action equivalent to running "git rm --cached"?
(Edited to simplify question)
I have found the answer. Team->Untrack is indeed the equivalent of "rm --cached". However there is a known bug which produces weird behaviour when you untrack and then try to commit.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=363405
Team -> Advanced -> Untrack
did the job (git rm --cached) for me.
I had the same problem, after not initially including directories and files in .ignore. I also tried "Untrack" and "Remove from index" possibility, non of which helped(due to the still unresolved Egit issue).
So, in the end I deleted files locally (leaving the project all in bugs), committed and pushed it to the github, and then undid the delete locally and added files to .ignore.
Very unelegant, but it worked.
I lost a lot of time and nerves on it, and I hope this helps someone.
Another option, similar to what Sri Sankaran suggests in the comments, is to update the index in order to assume no modification to your config file:
On the preferences, in Egit, you can list "assumed unchanged" files
:
The file remains versioned and on the disk, but no modification will be detected on it.
If you need to delete invisible folder(or file) from eclipse project:
Add folder(or file) to .gitignore file;
Replace folder to another directory
Team add to index, commit and push
Replace folder(or file) to the project folder

Get eclipse CVS to forget about removed directory

I'm looking for a way to convince Eclipse that a directory has indeed been removed from the CVS repository, permanently?
With regular command line CVS I would just edit CVS/Entries in the directory's former parent. With Eclipse, I've tried removing the directory from the Project Explorer view, removing the appropriate line in CVS/Entries, recreating the directory in PE so that it might be removed on update or synchronization, synchronize without recreating the directory, and probably other things that I've since forgotten, and nothing worked.
The directory has been entirely removed from the CVS repository, so I'm not talking about just pruning empty directories here. The error I am seeing is:
The server reported an error while performing the "cvs update" command.
Project: cvs update: cannot open directory /usr/local/cvsroot/one/two/three/removed_directory: No such file or directory
My project contains all of the contents from /usr/local/cvsroot/one/two. I do not get this error when I navigate to "three" and update from there. I only get it when I update from the project root.
One (quite imperfect) solution for this problem is, beside to check-out the project again, to remove CVS information stored by Eclipse.
Go in the right-menu under the project > Team > Disconnect, and check the radiobutton "Also delete the CVS meta information from the file system". Now your project is unshared and has no more CVS information into it. Then you just have to do Team > Share project, select the previous repository location, and you're done (CVS will detect by itself that the project is up-to-date and won't update nor commit anything, of course).
A folder that has been deleted in the cvs repository by hand won't then be proposed anymore by CVS under Eclipse to be commited.
Beware that on a big project with many files, depending on the speed of your network, the re-share may take some time.
Sometimes it may indeed be easier to delete the project and pull it off again from CVS.
I fought this same thing for several hours a couple of separate times. I just gave in and re-checked out the project. That seemed to work like a charm
Handling of directories in CVS is not perfect. This and many other reasons caused in creating more complete SCM tool subversion.
CVS can create directory, but can not remove it. From CVS point of view, to remove directory you need to remove (cvs rm) all files in directory. But directory is still present in CVS and there's no way to remove it. Hovewer, CVS propose a "hack" to hide such "deleted"/empty directories by executing "cvs up -P" (see here).
So, for CVS command line, I wouldn't mess with parent directory CVS/Entries file, but rather use "cvs up -P" described above.
The directory will be listed in the CVS/Entries file under the parent directory. Remove the entry in the Entres file and the directory. Eclipse should recognize the directory has been removed.
Refactoring directories in CVS is problematic. Due to the way CVS handles history one of the following usually applies:
The history of files moved to new locations appears to disappear. (It is located in the history of the old location.)
The history of files is retained, but files appear moved when checking out versions prior to the move. (Files were moved in the repository, rather than in a sandbox.)
Removing or moving directories in the repository generally creates problems for clients. It helps to retain directories and only move or remove files. Normal processing moves deleted files to an Attic sub-directory.
In the Eclipse CVS synchronization perspective, did you try the 'Override and update' option?
If the files/folders are already deleted on the repository, from the Eclipse project perspective, "replace with"->"latest from HEAD" on the folder containing deleted elements