You can recover data, i.e. unformat a hard drive on a Mac, by either using the Backups feature on macOS, or scan it using Disk Drill:
Download Disk Drill and install it on your Mac.
Open Disk Drill.
Select the drive you want to unformat.
Scan it and choose the files you want to retrieve.