How to undo the deletion of my .git/ folder? - linux

Earlier today I was having trouble pushing changes to my GitHub. I stagged several commits but kept getting the message "nothing to commit. branch is up to date". Long story short, I used the rm -rf command to delete my .git/ folder and I re-initialized another .git/ folder. I also deleted my repository and created a new one.
I then noticed my entire code in my text-editor (Atom) had changed and saved itself. Majority of my code went back to being as it was a month ago, with a tiny bit of code that I wrote last week. I contacted GitHub support and was about to get my repo restored. Unfortunately, I had not pushed my code to my repo in a month so of course that was not helpful. I had no idea that deleting my .git/ directory would completely alter my entire project without doing a pull request.
Is it possible to undo the deletion of the .git/ folder? I've seen questions and answers regarding the deletion of other files but not the .git/ folder itself. When I use commands such as git checkout ^HEAD 'fileName', I just get an error. When I use git log I just get the commits from the re-initialized .git/ folder, as expected.
Is there anything I could do to revert everything I did this morning?

Sadly there is no easy way to bring back a folder that you deleted with rm...
rm gets rid of your files for good, there is no "Trash" folder like you would find on Windows. That's the case for your .git/ folder just like it is for any other file.
Depending on your filesystem, you could still give a try to this tutorial on Ext2fs undeletion.
Don't forget to backup your code before doing that kind of hazardous operations.

Related

Troubles with deleting files from GitLab Master and Local (Student)

I am currently doing an end of year project and we're using GitLab. This is the first time I am using this and was confident about it until the following problem occurred.
After creating the clone, I've been working on my project and committed quite a few files to the school server by using git push after doing the prerequisites of git add and etc.
Now, I've decided to completely start again. I deleted everything manually from GitLab and then all the files from within the folder where the clone directs to. I started working on my new work in a separate folder - while still working on my new file, I decided to move all the files to the previous file where I deleted everything, where the clone was originally set for GitLab to save my files within the schools server.
When typing git status, the following appears (Please excuse the picture instead of me inserting the code in here. I tried entering the output on the console in here but was having editing problems).
I don't understand how to fully delete everything. So, I want to get rid of all Changes to be committed: and Untracked files:.
If you want to push there nothing to do with git status . git status only shows what been added to your repository before commit.

Git undo a change in a folder that was a part of .gitignore

I am building a theme for NodeBB and the theme lives inside the node_modules directory. Pulling in from master last night I have a new .gitignore my file had ignore all node_modules except for my theme, well since this is a new .gitignore it didn't track my changes.
Then I made changes to my theme without it being tracked. I decided to merge with my repo, after some conflicts took a step back then did npm prune now this pruned my theme, I spent the last hour making changes that I am not sure I can get back.
My question is since the folder was not being tracked is it possible to undo the npm prune and recover the theme within node_modules?
Sadly, I think you won't be able to get your files back.
If you added the files or the directories to .gitignore, then git wasn't tracking them. So you cannot get them back with git, unless you used to have them in the repo, but even if you did, the latest changes that you lost would not be part of the repo. Sorry for the negative answer.
However, all is probably not lost right now. If you immediately unmounted the file system or remounted it read-only as soon as you realised you deleted your theme, you could always try a file recovery tool such as photorec.

Creating SVN Repo and Checking Out

I'm moving my current server contents to a new one, and am currently in the process of setting up SVN. I'm fairly unfamiliar with SVN, typically using it to the extent of commits and updates.
I have two locations that I use SVN on the old server:
PROD location:
/var/www/html/new_dwutils/
and local:
/home/{user_name}/public_html/new_dwutils/
My interaction svn-wise is normally committing and updating at the /new_dwutils/ level.
Note: Running svn --version says I'm at version 1.6.11 for both servers.
I'm now trying to recreate this structure on the new server. My initial thought was to create the svn repo using something like:
svnadmin create /var/www/html/new_dwutils/
This creates the repo dir, but, when I copy my files into the dir, I am unable to do svn commands like status. However, when I go into a sub-dir of the copied data, I can use the svn commands.
This has me thinking that the repo is /new_dwutils/ and the copied data is considered a project? And the sub-dirs are working copies then?
Going off that thought, I deleted the repo, and made the html dir a repo:
svnadmin create /var/www/html/
I then copied my new_dwutils dir, and sure enough, I was able to do svn commands like I use too. What I've noticed is that when creating the repo, a few things are added that were not on the previous server: conf/, db/, format, hooks/, locks/, and README.txt. I get that these are svn files, but I'm not seeing the .svn file. I know that there was an update for svn that "removed" .svn files, but these files are now in /var/www/html/.
Now I want to setup my local working copy.
I've been doing (location /home/{user_name}/public_html/):
svn checkout file:///var/www/html/
Problem is it copies the html/ file, but nothing in it, and I don't want the html/ file I want the html/new_dwutils/ file.
I feel like I'm doing it wrong from the start, and would greatly appreciate some explanation on how to get on the right track. A step by step would be extremely useful, and if further clarification is need for files or directory paths, I would gladly detail.
Thanks!
The Subversion Manual will answer all of your questions.
If you're making a Subversion repository under /var/www.html, I'm assuming you're using Apache httpd as your server. Look at Chapter 6. If you already have a repo, create a dump file, then use that dump file to recreate the repo. Look at Chapter 5 on moving repositories.
If you don't know anything about Subversion, or are confused by the difference between the repository location directory and a working directory, read the on-line manual. It's one of the best pieces of documentation I've seen.
From description of your question it appears that '/var/www/html/new_dwutils/' is your working copy and not a repo.
Go to '/var/www/html/new_dwutils/' on the old server and type "svn info" this should give you location of the old repo. You should simply be able to 'svn co ' into the new location to checkout a copy of all your files from the old server (everything that is checked in - you will not get anything that is not checked in on the old server).
However, if your repo was local on the old server and you want to move it to your new server too. Then you can simply copy the entire folder to the new server and access it directly using its new location in 'svn co' command.

SVN Endless Loop - [file] "does not exist in repository"

This has been plaguing me for a week.
SVN keeps telling me that a certain file "does not exist in repository".
Fine. Let's just delete it. Forget about it. Ignore it. Whatever. I don't really care about this file (especially if it continues to fail the nightly check-in).
The most bizarre part? A "restore" will actually RESTORE the file from the repository, so its there (corrupted, maybe?).
...and this has to be the icing on the cake. If I delete the file through Windows Explorer, SVN will RESTORE the file from the repository, and right after that state that it doesn't exist in the repository. WTF?
Does anyone have a clue how to get rid of this?
I've already tried clean-ups, reversions, deletions and anything else imaginable, but this one has me stumped.
Thanks for any tips you might have...
It seems most likely that you have corrupted your local working copy, e.g. by moving folders or some other manipulation that you did with windows explorer but should have done through the TortoiseSVN context menu. The information inside the .svn folders now no longer matches the state of the working copy, which is confusing Subversion.
To fix this, delete the parent folder ("Originals") in your working copy with windows explorer (NOT with TortoiseSVN). Then do a TortoiseSVN "update" at the root of your working copy. This should restore the folder in working order.
Another option is to discard your working copy entirely and do a fresh checkout.
Note that the next release of Subversion (1.7) will reduce the opportunities for corrupting your working copy by centralizing all metadata in a single .svn folder at the root.
I've had similar problems with corrupted working copies. Sometimes the working copies have a lot of pending changes but unable to checkin. To resolve this, I use the following approach (svn 1.7+):
Checkout a fresh working copy into a new directory (path2)
In the fresh working copy, if the offending file is there, delete it if needed.
Commit the fresh working copy
In the fresh working copy, delete everything except the .svn directory
Copy everything from the old working copy except the .svn directory into the fresh working copy.
Commit the fresh working copy again
Delete (or backup) the old working copy
Rename the fresh working to the old working copy (path2 to path)
I had faced a similar problem wherein i had a folder, for example "FolderA" which consistently shows in svn update even though I had deleted it.
It would not even show in the folder list but svn would still recognise it as if it exists.
I followed below steps:
1.Create same folder name for which svn was giving error in the same file location
2.Added it to svn checkout. Since it gave conflict errors, i resolved it using the svn option to resolve.
3.Deleted the folder and committed my svn.
Error was resolved

Tortoise Check-in error Checksum mismatch

I cannot figure out why I get this error during check-in. I checked in successful only a few hours ago so not sure why now it's complaining
Error: Commit failed (details follow):
Error: Checksum mismatch for
Error: 'C:\sss\sss\trunk\xxxx\.svn\text-base\Header.ascx.svn-base'; expected:
Error: '3cee96f580409a1711a47541a07860dd', actual: 'a5fc0f8819b88bf32ab38d4c9a6b0654'
Error: Try a 'Cleanup'. If that doesn't work you need to do a fresh checkout.
I got latest and also performed a clean-up which said successful so not sure what else to do.
Something has gotten out of sync or has become corrupt, and because it's in your .svn BASE directory, unless you are confident tinkering with this, you're probably better off deleting the parent of the .svn directory and then perform an update. Of course, take a backup or see if an export works before doing this, so you don't lose any changes.
FWIW, I get this sometimes with our library references where Visual Studio seems to keep a lock on some files (even though it's not compiling) and won't let me update them. I believe this is related to the xml documentation files.
Note: Subversion 1.7+ implements a new working copy approach which centralises the meta data, and it now has a single .svn directory at the root of your working copy. Your best bet is a cleanup, failing that a fresh checkout into another directory and export or file copy the corrupted working copy except for the .svn directory, over to the fresh checkout, and commit any local changes.
Looks like one of your SVN files is corrupt. First, check-in everything that can safely be checked in, and make sure to backup everything. Then fix the offending file - usually this involves deleting it from your repository. This should be okay if you're checking in a new version anyway.
I received a similar error after our project repository was moved to a new server. Try reverting your file and reapplying your changes.
I had same problem after googling for some help found articles that suggested to override the checksum in the .svn\entries file. But in that file the checksum was actually as the the expected one in the error message.
To fix the problem, I navigated to .svn\text-base dir of problem file's directory and found out that there's a copy of the file i was trying to check in changes for. I opened that file in Notepad++ and replaced it's content with content of the file to be commited and i was able to commit afterwards.
But just in case, make a backup copy of the .svn\text-base file.
I think this happened because i did an svn update before commit because it complained that my version is outdated. Anyway, it's fixed for me and hope my solution helps someone else too.
With Tortoise SVN, I choose to delete the file in Repo Browser.
First back up the problem file. and use Repo Browser delete the problem file in it, then update local folder so the file in local folder is deleted. Then copy back the backup file and Add > Commit, then I can update successfully.
The disadvantage of this method is the history of this file will be removed.
Also see another post.

Resources