git - Restore deleted files from commit -
i've done following series of steps , don't know how recover files.
- git add file.txt
- git commit -m "message"
- rm file.txt
- git commit -am "message"
ideally should have pushed changes after step 2 , delete forgot. there way recover file?
many thanks!
you can recover file previous revision checkout
command:
git checkout head^ file.txt
or, if haven't pushed commit yet, might rather want reset commit instead:
git reset --hard head^
this reset working tree same state of previous commit. changes after previous commit gone.
if don't want changes gone, undo act of commit itself, can reset without --hard
option, , restore deleted file with:
git reset head^ git checkout file.txt
Comments
Post a Comment