2

How to un-delete / recover local files from git pull?

Scenario:

  1. I have local files in a folder
  2. I do git init
  3. "git pull https://.." from server
  4. All the local files is deleted

Can I get my deleted files back?

Thanks

Chris G.
  • 23,930
  • 48
  • 177
  • 302
  • Uhh, do you have a backup? Otherwise, unless these files show up in some sort of garbage can, I think your out of luck. Sorry! – happy coder Jan 23 '13 at 07:29
  • Are the local files just deleted, or are they replaced with new files from the server that have the same name? I've now tried `touch a b c; git init; git pull `, and I got the new checkout along with the old files `a`, `b`, and `c`. Were your local files ever staged or committed? – user4815162342 Jan 23 '13 at 07:37
  • Nope, the files was never staged. I only did "git init" in the folder, before doing "git pull". – Chris G. Jan 23 '13 at 07:43
  • Did the files have the same names as (some of) the files that `git pull` brought in? – user4815162342 Jan 23 '13 at 07:44
  • No, the local files that was deleted was in a sub folder that does not exist in the server repository. – Chris G. Jan 23 '13 at 07:49
  • 1
    I still cannot repeat that behavior with `mkdir bla; touch bla/{a,b,c}; git init; git pull `, but it doesn't really matter for your question. Bad news spelled out in the answer... – user4815162342 Jan 23 '13 at 07:52
  • [Why git rm --cached not remove local ever tracked file but others](https://stackoverflow.com/q/55663325/6521116) – LF00 Apr 25 '19 at 01:03

1 Answers1

1

If the lost files were never staged or committed, there is no way to restore them using git. At this point, the only thing you can do is try to restore them using third-party undeletion utilities written for your OS.

(In my tests git doesn't delete local files at a git pull, but at this point how the files got deleted is not relevant to the question, only to git's reputation for not deleting user data.)

user4815162342
  • 141,790
  • 18
  • 296
  • 355
  • Just ran across a similar situation, and can't reproduce it. So I asked how it could happen. See http://stackoverflow.com/questions/42625566/what-would-make-git-delete-local-files-during-git-pull-rebase – martin jakubik Mar 06 '17 at 12:24