If you file bankruptcy after the foreclosure sale, you can discharge the deficient balance that may result from the mortgage loan, but you can’t get the home back. You need to file bankruptcy prior to the foreclosure sale to stop it.
On the other hand, if you file bankruptcy before the foreclosure sale takes place, it stops the foreclosure. You can propose a repayment plan in a chapter 13, or you can simply file a 7 to stop the foreclosure sale and hope that they’ll work with you on a loan mod.
But no, filing bk after the fact will not bring the home back.