1

I accidently deleted source directory.. I thought I was deleting another directory. But I have last commit that is where I need to revert back.

I have two branches:

master
dev1

On dev1:

git add .
git commit -m 'commit message'

Then:

git checkout master
git merge dev1

Then I accidently deleted whole repository.

Then I hard reseted to last commit and I see it shows that all correct changes were made. But when I got to my directory it is old directory (I copied old one, but it is not being deleted from here). What Should I do?

Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
Andrius
  • 19,658
  • 37
  • 143
  • 243

3 Answers3

0

If you removed the whole repository, you'll have to get it back from a backup (or reconstruct it from any other repositories you pulled from, or pushed to). There isn't anything for git to work on anymore.

vonbrand
  • 11,412
  • 8
  • 32
  • 52
0

Do a

git log

to get the hash of the previous commit and then do a

git revert your_hash_here

to revert the commit. Finally do a

git push

to push your changes and fast forward them to master

Saif Asif
  • 5,516
  • 3
  • 31
  • 48
  • I tried it, but it gives this error: `cb963f5..f37d6e4 new_medical_card_rev1 -> new_medical_card_rev1 ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '/home/oerp/openerp70/openerp/source/addons/ambulance_system' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.` – Andrius Feb 26 '14 at 13:16
0

It depends on what you mean by "deleted the whole repository". From your comments on other answers I think you haven't deleted everything, and if you can still execute git commands in that directory successfully, you can simply git reset --hard master (which this question explains in more detail).

If you've completely hosed your entire git repository directory on the localhost, since you pushed your changes to remote, you can simply git clone <example.com/myrepo.git> and it will pull everything down from the remote.

Community
  • 1
  • 1
L0j1k
  • 12,255
  • 7
  • 53
  • 65