Deleted 2 months work with Git. How to get them back?
I don’t really know what I’ve just done so I’m just going to give a kind of timeline.
I was trying to set up a gitHub repository today for the first time. I have a folder where I keep all the files from my site and it had a .git folder. Every so often I was committing changes etc and everything seemed ok.
Today I tried to merge two branches of the project I was working on. I tried “merge” and “rebase” commands but I couldn’t really understand what was happening or what I was doing so I decided I’d just start over with git.
I pulled the .git folder out of my website folder (I didn’t delete it which I guess could be my saving grace here). Did a new git Init in the folder and committed the website files to it.
That’s when I noticed loads of files were missing. I think they’re still in the first .git folder. Is there a way I can restore a directory from this folder?
One Solution collect form web for “Deleted 2 months work with Git. How to get them back?”
I’m surprised that you’ve been working for two months with git and decided that starting over was that best way to recover from a failed rebase, it should be a lot easier.
You should be able to recover your old commits into the new repository without too many problems.
You can add a new remote that is your old saved repository:
git remote add old /path/to/old/saved/.git
Then you can fetch all of the old history.
git fetch old
Then you can open up a history browser (e.g.
gitk --all) to have a look at the old history.
You can check out versions of missing files with a command such as:
git checkout old/master -- path/to/missing/file
old/master refers to the master branch in your old repository, you can use the id of any branch or commit here, though.