1

I mistakenly deleted a lot of files from my workspace, i also have a lot of modified files. How do i revert only the deleted files(and not the modified ones) in one go?

deleted:    src/main/content/jcr_root/components/mega-menu/directives/dropdown.js
deleted:    src/main/content/jcr_root/js/components/mega-menu/directives/sub-menu.js
deleted:    src/main/content/jcr_root/js/components/mega-menu/mega-menu-module.js
deleted:    src/main/content/jcr_root/js/components/mobile-menu.js
modified:   src/main/content/jcr_root/js/components/product-list.js
modified:   src/main/content/jcr_root/js/components/product-shipping.js
modified:   src/main/content/jcr_root/js/components/reward-category.js

I tried this in one of my local feature branches: git reset HEAD \* and then git checkout --, but this seems to revert both deleted and modified ones.

SubSul
  • 2,523
  • 1
  • 17
  • 27
  • Have you tried http://stackoverflow.com/questions/215718/reset-or-revert-a-specific-file-to-a-specific-revision-using-git – hypeJunction May 26 '16 at 09:12
  • yep, this works for a single file, in my case i have many deleted, i'll have to run that command several several times! – SubSul May 26 '16 at 09:16
  • 1
    And this? http://stackoverflow.com/questions/953481/find-and-restore-a-deleted-file-in-a-git-repository – hypeJunction May 26 '16 at 09:22
  • As an aside: Git works best when your commits are small and have one logical unit of change in then; it seems to me like your current commit may have been too large/too much in one go to begin with (of course, it's hard to tell without actually knowing the commit). – MicroVirus May 26 '16 at 09:31
  • @MicroVirus I have close to 10 files which have been modified and ready to be committed and more than 20 files which have been mistakenly deleted. All of them across varied folders. – SubSul May 26 '16 at 09:58
  • @hypeJunction Second link didnt work out either. – SubSul May 26 '16 at 10:00
  • 2
    Have you tried all suggestions from 2nd links? I would suspect this answer should work: http://stackoverflow.com/a/4332209/677409 – hypeJunction May 26 '16 at 10:02
  • Starting from this commit and a clean working directory (`git stash` if necessary), maybe you can use a `git reset --mixed` followed by a `git rm -- *` to get all the removed files in the staging area, then commit that, then add all modified files, commit, then on your main branch just cherry-pick that modified commit. I haven't tried this, though. – MicroVirus May 26 '16 at 10:02
  • @hypeJunction buddy, u saved my day, that command worked. Thanks. – SubSul May 26 '16 at 10:22
  • @MicroVirus Thanks for your suggestions as well. – SubSul May 26 '16 at 10:25

0 Answers0