2

Mistakes were made, yes.

My storage folder of my application was committed to my repo and when I tried to sync up a new update that I committed to my repo and sent to my server I ran git reset --hard && git clean -df.

Little did I know that any files in my storage folder that weren't in my previous commit (which had the storage folder committed WITH files) - would be deleted.

forge@onaxim-crm:~/api.crm.onaxim.com.au$ git reset --hard && git clean -df
Checking out files: 100% (1049/1049), done.
HEAD is now at 6776b4d v2.3updates
Removing storage/customers/1/
Removing storage/customers/1017/
Removing storage/customers/1032/
Removing storage/customers/1039/
Removing storage/customers/1044/
Removing storage/customers/1058/
Removing storage/customers/1084/
Removing storage/customers/1086/
Removing storage/customers/1094/
Removing storage/customers/1095/
Removing storage/customers/1101/
Removing storage/customers/1102/
Removing storage/customers/1106/
Removing storage/customers/1109/
Removing storage/customers/1111/
Removing storage/customers/1112/
Removing storage/customers/1113/
Removing storage/customers/1114/
Removing storage/customers/1115/
Removing storage/customers/1116/
Removing storage/customers/1117/

I check the directory and the field have been removed so is there any way to recover them?

I read something about maybe using git fsck --lost-found?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Tim Rowley
  • 420
  • 4
  • 15
  • Were these files ever committed? If so, no problem. The commit containing them is still there. – matt Feb 12 '21 at 07:04
  • Hi, thanks for the response. Only half of the storage/customer/xxxxx were committed from a previous accidental push from the server. So, the first half is actually still on the server as Git just removed what wasn't committed and pushed to my repo. The second half of the files `storage/customers/` > 1016 was never committed. – Tim Rowley Feb 12 '21 at 07:37
  • Don't confuse commit with push. Until some time passes, all commits you have ever made locally still exist and are keeping all files that they contained. If a file was _never_ committed at all, however, that is no business of Git and if you delete the file that is your affair. – matt Feb 12 '21 at 18:36
  • Some questions linked: https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git/22303923 and https://stackoverflow.com/questions/11094968/in-git-how-can-i-recover-a-staged-file-that-was-reverted-prior-to-committing/58853981 – Philippe Feb 12 '21 at 21:05

1 Answers1

0

A git reset --hard does not move HEAD to a different commit, so if sync involved a pull, you might still see your content in the previous commit (the one before pull) with, for testing:

git restore @~ -- .

My storage folder of my application was committed to my repo

If by "committed", you mean only "git add" (but no actual git commit), then yes, a git fsck --cache --no-reflogs --lost-found --unreachable HEAD is needed to start checking out content of deleted staged files.

The OP Tim Rowley does mention in the comments:

About half of the /storage/customer/xxxx folders are actually in the GitHub repo online from a previous commit.
The other half has never been committed or pushed as they have only been on the server. Thus, I must have accidentally made a push from my server with the first half - and the second half was new. I need the second half back.
The second half never interacted with Git, s

In that case, only file recovery tools might help restoring those files.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi thanks for your response. About half of the /storage/customer/xxxx folders are actually in the Github repo online from a previous commit. The other half has never been committed or pushed as they have only been on the server. Thus, I must have accidentally made a push from my server with the first half - and the second half was new. I need the second half back. – Tim Rowley Feb 12 '21 at 07:35
  • @TimRowley Was the second half added to your index locally? – VonC Feb 12 '21 at 07:36
  • the second half never interacted with Git, so I don't believe so. – Tim Rowley Feb 12 '21 at 07:39
  • @TimRowley Then you would need file recovery utility in order to restore those deleted files (Git or not) – VonC Feb 12 '21 at 07:45
  • I fear that would be the outcome. Thanks for your assistance. – Tim Rowley Feb 12 '21 at 07:48
  • @TimRowley I have edited the answer to reflect the conclusions from those comments, and I have added a link to a list of open-source file Linux recovery tools. – VonC Feb 12 '21 at 07:55