1

I will explain what I have done, which seems to have destroyed a folder with files I was working on.

I have a git project, which is fine, and I also have a folder (outside this git project, and no part of any git project) where I had some scripts and some files I generated. I wanted to integrate this folder into the git project, so I moved it there to a right location.

I did a git status, and it said that the new folder was untracked, so I did a

git add newfolder

I then did a git status, and it showed hundreds of pickle *.p files which I had moved, but that I didn't want to commit or push these to the server. So I created a new .gitignore file to ignore these .p files.

I checked git status again, but it was too late, and the .p files where already there, so this is when I did my first mistake. I thought "I should undo the last commit" (even though I never committed about adding this new folder so far) and I did

git reset --hard HEAD^

After this I did a git status and it said I was a pull behind (some changes I did yesterday to that git project) so I did git pull.

After this, all the files in newfolder disappeared. The only thing still around are the folders I had inside (empty) and some hdf5 files I had in the root .gitignore.

So my question is, is there any way to recover newfolder?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dr Sokoban
  • 1,638
  • 4
  • 20
  • 34
  • 2
    Possible duplicate of [Recover files that were added to the index but then removed by a git reset](https://stackoverflow.com/questions/10782978/recover-files-that-were-added-to-the-index-but-then-removed-by-a-git-reset) – Calum Halpin Jul 21 '19 at 11:15
  • This old answer can help you see the blobs that Git has saved from an aborted `git add` - the same thing applies to a `git add` that was followed by a `git reset` like you describe here. https://stackoverflow.com/a/54237450/3216427 – joanis Jul 21 '19 at 17:59

1 Answers1

1

If you never committed these new files anywhere, then unfortunately they may be lost. Perhaps you have them backed up somewhere.

Just for information, what you should have done to these Pickle *.p files is:

git reset -- some/path/to/pickle.p

This would simply undo the git add step which you did to these files.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360